Tuesday, April 15, 2014

How to install ImageMagick with MAMP

1. Install Homebrew http://brew.sh/
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
2. Install ImageMagick for the PHP version your MAMP is running.
brew search imagick
brew install php55-imagick
After installation, the ImageMagick PHP extension is created in /usr/local/Cellar/php55-imagick/3.1.0RC2/imagick.so
3. Disable the DYLD_LIBRARY_PATH variable in Apache's environmental variables.
vi /Applications/MAMP/Library/bin/envvars
Comment out the following line:
export DYLD_LIBRARY_PATH
4. Update php.ini to include imagick.so
vi /Applications/MAMP/bin/php/php5.5.3/conf/php.ini
Add the following line.
extension="/usr/local/Cellar/php55-imagick/3.1.0RC2/imagick.so";
5. Restart MAMP
6. Check if imagick is included in phpinfo()

Monday, March 3, 2014

A simple copying directory function

function recurseCopy($src, $dst, $excludeFileType=array()) {
    $dir = opendir($src);
    mkdir($dst, 0755, true);
    while(false !== ( $file = readdir($dir)) ) {
        if (( $file != '.' ) && ( $file != '..' )) {
            if ( is_dir($src . '/' . $file) ) {
                $this->recurseCopy($src . '/' . $file, $dst . '/' . $file, $excludeFileType);
            }
            else {
                $filePathInfo = pathinfo($file);
                $ext = '';
                if(!empty($filePathInfo['extension'])){
                    $ext = $filePathInfo['extension'];
                }
                if(empty($ext) || !in_array($ext, $excludeFileType)){
                    copy($src . '/' . $file, $dst . '/' . $file);
                }
            }
        }
    }
    closedir($dir);
}

Friday, February 28, 2014

How to get WordPress posts permalinks using SQL(database) alone

SELECT wpp.post_title, wpp.post_type, wpp.guid, wpp.post_date, CONCAT( wpo_su.option_value, REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( wpo.option_value, '%year%', DATE_FORMAT( wpp.post_date, '%Y' ) ) ,'%monthnum%', DATE_FORMAT( wpp.post_date, '%m' ) ) , '%day%', DATE_FORMAT( wpp.post_date, '%d' ) ) , '%postname%', wpp.post_name ) , '%category%', wpp.post_type ) ) AS permalink
FROM wp_posts wpp
INNER JOIN wp_options wpo ON wpo.option_name = 'permalink_structure'
INNER JOIN wp_options wpo_su ON wpo_su.option_name = 'siteurl'
WHERE (
wpp.post_type = 'post'
OR wpp.post_type = 'page'
)
AND wpp.post_status = 'publish'

Tuesday, February 25, 2014

A Target campaign


A micro site that allows user to get a free mp3 download after Facebook authentication. The site is written in PHP with MySQL database.
Application features:
  • Limits one download per user. 
  • Integration with real-time music purchasing and download.
  • Location restriction by user IP address.
  • Integration with Email injection services.
  • Twitter, Instagram and Facebook user authentication process.
  • Works on both desktop and mobile web browsers.
  • Supports high volume of traffic.

moreshakira.target.com

Monday, November 18, 2013

How to get iDevice hardware model

size_t size = 100;
char *hw_machine = malloc(size);
int name[] = {CTL_HW,HW_MACHINE};
sysctl(name, 2, hw_machine, &size, NULL, 0);
NSString *hardware = [NSString stringWithUTF8String:hw_machine]; //e.g. iPhone4,1
free(hw_machine);

Wednesday, November 6, 2013

How to resign an IPA with new bundle Id, certificate and entitlements

  1. Create an Entitlements.plist using Xcode
    1. Include the following keys values in the plist file. 
      1. application-identifier (String) -> 3Q83MXXZGH.com.company.appname
      2. get-task-allow (Boolean) -> NO
  2. Put the Entitlements.plist in the same folder of the app.ipa file
  3. Unpackage the app
    1. unzip app.ipa
  4. Delete current code signature
    1. rm -rf Payload/MyApp.app/_CodeSignature/
  5. Open Payload/MyApp.app/Info.plist in Xcode and update the bundle ID(CFBundleIdentifier)
  6. Copy the new .mobileprovision file to Payload/MyApp.app/embedded.mobileprovision
  7. Run the codesign command
    1. codesign -f -s "iPhone Distribution: Company Certificate" --resource-rules Payload/MyApp.app/ResourceRules.plist --entitlements Entitlements.plist Payload/MyApp.app
  8. Repackage the app
    1. zip -qr app-resigned.ipa Payload/
Sample Entitlements.plist

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">


 application-identifier
 3Q83MXXZGH.com.company.appname
 get-task-allow
 


Tuesday, October 8, 2013

How to add parallax effect to your apps

UIInterpolatingMotionEffect *interpolationHorizontal = [[UIInterpolatingMotionEffect alloc]initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
interpolationHorizontal.minimumRelativeValue = @-10.0;
interpolationHorizontal.maximumRelativeValue = @10.0;

UIInterpolatingMotionEffect *interpolationVertical = [[UIInterpolatingMotionEffect alloc]initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
interpolationVertical.minimumRelativeValue = @-10.0;
interpolationVertical.maximumRelativeValue = @10.0;

UIMotionEffectGroup *interpolationGroup = [[UIMotionEffectGroup alloc]init];
interpolationGroup.motionEffects = [NSArray arrayWithObjects:interpolationHorizontal, interpolationVertical, nil];

if([aView respondsToSelector:@selector(addMotionEffect:)]){
    [aView addMotionEffect:interpolationGroup];
}