Saturngod

What's on my mind

Download All Photos From Flickr

After flickr changing uploader is only for pro account , I decied to move to the google photos. However, it’s not easy to get the original file size. I found , bulkr but I feel like it’s expensive and not worth it for only download all photos.

So, I decied to rewrite myself. I wrote the script and you can get the script in github.

First , we need to get oAuth Token and Secrect. So, to get this two , you need to run on browser. After got these two , just update at download.php. After that , run php download.php. It will download all photos. I don’t want screenshot and only photo. So, I use content_type=6. If you want all , just remove that one.

I have over 55 GB on flickr and it took over 24 hours to download for getting back all original photos for me.

Static Library to Framework

I have no idea , new version of cocoa pods was not working with static library. It was working before and I didn’t change any code in podspec. Xcode couldn’t find my library when it was building.

So, I decided to change current static library to the framework. I wrote about how to build enable bit code for static library.

I don’t want to change current my code and current code cannot change to framework because it was using other static library inside , too.

I changed my build code like following


# build.sh 
folder="Release"
project_name="mycustomlib"
lib_name="libmycustom"
name_simulator=$lib_name"_simulator"
name_device=$lib_name"_device"

xcodebuild OTHER_CFLAGS="-fembed-bitcode" -target $project_name build
xcodebuild OTHER_CFLAGS="-fembed-bitcode" -sdk iphonesimulator -target $project_name build
rm -r build/Production-SDK
cp -r build/$folder-iphoneos build/Production-SDK
cp build/$folder-iphonesimulator/$lib_name.a build/Production-SDK/$name_simulator.a
mv build/Production-SDK/$lib_name.a build/Production-SDK/$name_device.a
cd build/Production-SDK/
lipo -create $name_simulator.a $name_device.a -output $lib_name.a
rm $name_device.a
rm $name_simulator.a
file $lib_name.a

# Time For Building Framework
rm -rf $lib_name".framework"
mkdir $lib_name".framework"

LIBTOOL_FLAGS="-static"
libtool -no_warning_for_no_symbols $LIBTOOL_FLAGS -o $lib_name.framework/$lib_name $lib_name.a
cp -r ./usr/local/include $lib_name.framework/Headers/
cp ../../fwInfo.plist $lib_name.framework/Info.plist

open .

You need to have fwInfo.plist for framework plist file. You can create easily framework plist file from the Xcode. File > Project > Framework & Library > Cocoa Touch Framework

After that copy the info.plist and change to fwInfo.plist. Put in same path with build.sh.

After running the build.sh , you will see framework file , too.

Unsplash Wall Android

Finally , I done the unsplash wall for android. At the new year night , I did that app for learning material design for Android. Not the complete product yet and I need to add floating button and toolbar instead of using menu.

Currently, it’s supporting

  • Showing Photos from Unsplash
  • Random Photo
  • Set desktop wallpaper
  • Download Photo
  • Download Original Photo

I need to do some changes on UI like

  • Use floating action bar
  • Toolbar

It also need to support Xiaomi Phone (now image is not saving in Xiaomio Photos App).

home

detail

You can download unsplash wall in google play store

Enable Bitcode in library file (.a)

After enable bit code in Xcode 7 , I couldn’t build .a file with embed-bitcode. Same problem for the zbar library , too. So, I cannot use my own library with .a file or cannot use the zbar for production. After searching from google , I found a way to build. We need to use the command line with xcodebuild.

I wrote the build.sh like following and same folder with myproject.xcodeproj

folder="Release"
project_name="mycustomlib"
lib_name="libmycustom"
name_simulator=$lib_name"_simulator"
name_device=$lib_name"_device"

xcodebuild OTHER_CFLAGS="-fembed-bitcode" -target $project_name build
xcodebuild OTHER_CFLAGS="-fembed-bitcode" -sdk iphonesimulator -target $project_name build
rm -r build/Production-SDK
cp -r build/$folder-iphoneos build/Production-SDK
cp build/$folder-iphonesimulator/$lib_name.a build/Production-SDK/$name_simulator.a
mv build/Production-SDK/$lib_name.a build/Production-SDK/$name_device.a
cd build/Production-SDK/
lipo -create $name_simulator.a $name_device.a -output $lib_name.a
rm $name_device.a
rm $name_simulator.a
file $lib_name.a
open .

In the build.sh , folder is your release folder name. zbar is using Distribution-iphoneos and Distribution-iphonesimulator .

If you using your own , it may be Release-iphoneos and Release-iphonesimulator. lib_name is your .a library name. In Zbar , it’s using libzbar . project_name is your traget to build. Sometime , lib_name and project_name is different in the project.

After chasing this two, you can run in terminal like

sh ./build.sh

Need to wait until finishing the build and then it will show your lib.a file. In the terminal , you can check , it’s showing what platform are supporting.

If it doesn’t support i386,x86_64,armv7,arm64 , you need to open your project. Go to Build Settings -> Valid Archtectures. Add all architectures like following

  • armv7
  • armv7s
  • i386
  • arm64
  • x86_64

Don’t forget to change Build Active Architecture Only to NO

Install Intl in PHP , Mac

To install Intl library for PHP in Mac , you need to install brew first.

Install Brew For ICU

First , update the brew

brew update

Search the ice package name.

 brew search icu

You will find like icu4c and install it.

brew install icu4c

Your icu4c path is

/usr/local/Cellar/icu4c/55.1

Version may not be same. You can check director at /usr/local/Cellar/icu4c/

After we got icu4c , we can install intl from peel.

[...]

Unsplash Wall

You may know the unsplash.com. It is Free (do whatever you want) high-resolution photos. It has a lot of photos and great for using as wallpaper for my iPhone and iPad. So, I created the unsplash wall. It’s using unsplash.it for backend API.

Unsplash Wall is simple and beautiful and showing the all images from unsplash.com.

cover image

You can get the full screen image when you click the photo and you can save or share.

full

share

Development

It was writting in Swift and nothing special. Very simple project and focus on clear and simple. So, I didn’t put so many function in there. I just want to see all images and save the photos. That all for now.

You can download Unsplash Wall From App Store , now.

Google Play Service With Genymotion

First you need to download following files.

If you want to know Android version from CyanogenMod , you can check at following.

  • Cyanogen 9.1 , Android 4.0.x
  • Cyanogen 10.0.0 , Android 4.1.x
  • Cyanogen 10.1.3 , Android 4.2.x
  • Cyanogen 10.2.1 , Android 4.3.x
  • Cyanogen 11.0 , Android 4.4.x

Installing

  • Open Genymotion
  • Drag and Drop the ARM Translation Installer v1.1 zip file Genymotion Virtual Device
  • Reboot The Genymotion Virtual Device
  • After reboot , Drag and Drop the Google Apps zip file to Genymotion Virtual Device
  • Reboot the Genymotion Virtual Device

After reboot you can find the Google Play Store in application list. Open play store and update all the google apps. After updating and downloading the apps, pull down the Notification bar. You can find to update google play store in notification.

ref: stackoverflow

Number padding with decimal

You may see some personal fincial app , you need to put the number like calculator.

Example : First it show 0.00

You enter 1

it will be like 0.01. And then press 5 , it will be 0.15. And then press 3 , it will be 1.53 .

So, how to write this one ?

Normal thinking way it, you need to check

  1. Append the string at the end
  2. Check first number is zero or not.
  3. If zero , remove it.
  4. Move the decimal posiotion.

A bit complicate. Actually it’s not hard like that.

Very simple way is

  1. Append the string at the end.
  2. remove .
  3. dvided by 100

That all. Very simple step.

Example with objective-c , it will be like

NSString* str = [NSString stringWithFormat:@"%@%@", txtAmount.text,string];
str = [str stringByReplacingOccurrencesOfString:@"." withString:@""]; 
txtAmount.text = [@"" stringByAppendingFormat:@"%0.2f", [str doubleValue]/100.0];

Custom Wintersmith Helper

Today , I was trying to add twitter card in my blog. It have a problem for twitter card description. Wintersmith didn’t support plain text for blog post. Blog intro already using the HTML code. So, I need to remove.

So, I create the custom helper like following.

Create a wintersmith-custom-helper folder under node_modules

In the wintersmith-custom-helper , it have 2 file. index.js and package.json .

In the package.json

{
  "name": "wintersmith-customhelper",
  "version": "1.0.0",
  "description": "Custom Helper For My Blog",
  "author": "saturngod",
  "license": "MIT",
  "keywords": [
    "wintersmith",
    "wintersmith-custom-helper"
  ],
  "main": "index.js",
  "dependencies": {
  },
  "devDependencies": {
    "vows": "0.7.x",
    "wintersmith": "2.x"
  },
  "peerDependencies": {
    "wintersmith": "2.x"
  }
}

I gave the module name is wintersmith-customhelper.

In the index.html

module.exports = function(env, callback) {
  env.helpers.getDescription = function(htmlcode) {
    var code;
    code = htmlcode.replace(/(<([^>]+)>)/g, "");
    code = code.substring(0, 255);
    code = code.replace("\n", " ");
    code = code.replace("\"", "");
    return code = code + " ... ";
  };
  return callback();
};

I create the getDescription helper for description.

After finish that, need to update the config.json

In the config.json , we need to put the plugin. So, it will be like

"plugins": [
    "wintersmith-tag",
    "./node_modules/wintersmith-custom-helper"
  ],

Done. So, we can call env.helpers.getDescription in our template.

- var plain = env.helpers.getDescription(page.intro)
meta(name='twitter:description', content="#{plain}")

It easy to create helper and you can also use .coffce instead of .js file for plugin.

Decimal Format In Android

Yesterday , I found a bug in the app that I working on. If it’s a indonesia language in phone , my app can’t work properly. Because Android didn’t return the decimal if we are using indonesia language setting.

Example :

String amt = String.format("%.2f",20.05);
Log.i("test","Amount is " + amt); //if indo language , it will return 20,00 instead of 20.05

I tested with DecimalFormat but same result.

DecimalFormat f = new DecimalFormat("##.00");
String atm = f.format(d); 
Log.i("test","Amount is " + amt); //if indo language , it will return 20,00 instead of 20.05

So, I am using like following for now.

String amt = String.format("%.2f",20.05);

if(atm.indexOf(",") != -1)
{
    atm = atm.replace(",", ".");
}

Log.i("test","Amount is " + amt);