Archive

Tag Archives: information

Actually, this website was my portfolio webpage before becoming a wordpress. It is moved to here: nicholasworkshop.com/portfolio. Using wordpress, I put the old webpage aside and always forgot to transfer the information from it to the front page. Anyway, I hope this can remind me of the projects and webpages I created.

Thank you for checking out this tutorial. Reading the discussions in this post, seems like there is quite a number of people having troubles to take screenshots with Galaxy S2. To clear any confusions, I summarized some information and added as followings. Hope you could make it too. Fingers crossed.

First, make sure your Galaxy S2 is running Android version 4 or above.

Volume Down + Power Key will work fine.
Press both keys at the same time gently. In about 1 second, screen capture would be done. A notification and an animation would be shown too.

Edited on 12 July.


Press and hold power and volume down button together. This is the way to take screenshot in the new Android system 4.0 Ice Cream Sandwich. After the Samsung Galaxy S2 updated to this new version, it uses this method instead of the way mentioned in my old post.

It’s quite often for a developer to make use of the user agent to determine what browser does a user used, especially for those who develop web services and websites. Recently I found a website which has a huge database of mobile device information, including the user agent string and even the functions supported in the device browser.

ScientiaMobile WURFL Explorer
http://www.tera-wurfl.com/explore/search.php?action=browse

Tera-WURFL Explorer – Samsung GT-9100 (Galaxy SII)
http://www.tera-wurfl.com/explore/?action=wurfl_id&id=samsung_gt_i9100_ver1

While using hit, it is really usual to have regrets on the commits done, especially the name used. In order to change those information in your repository, open terminal (or cmd in windows), go to the folder of your git repositoy, and run the following commands. Remember, replace “old_name”, “new_name” and “new@email.address” with your own information.

git filter-branch --commit-filter '
  if [ "$GIT_COMMITTER_NAME" = "old_name" ];
  then
    GIT_COMMITTER_NAME="new_name";
    GIT_AUTHOR_NAME="new_name";
    GIT_COMMITTER_EMAIL="new@email.address";
    GIT_AUTHOR_EMAIL="new@email.address";
    git commit-tree "$@";
  else
    git commit-tree "$@";
  fi' HEAD

I have been working with Cocos2D for a while and I am still a newbie. The way to deal with animations in Cocos2D 1.0.0 – the stable version currently – is different from the way before using CCSpriteSheet. Now Cocos2D adapts animations as cache shared in the project using CCSpriteFrameCache. It also requires a plist file as well as a texture file.

First, put the following assets into the project “Resources” folder to let the program use.

  • grossini.plist – The file contain the animation information such as frame details.
  • grossini.pvr.gz – The texture file in pvr format which allow better performance in Cocos2D.

Second, add the following codes into the function init. Take a look at the comments for program explanation. =]

// Capture the window size
CGSize size = [[CCDirector sharedDirector] winSize];

// Load the plist into the cache
CCSpriteFrameCache *cache = [CCSpriteFrameCache sharedSpriteFrameCache];
[cache addSpriteFramesWithFile:@"grossini.plist"];

// Create sprite with the first frame
CCSprite *sprite = [CCSprite spriteWithSpriteFrameName:@"grossini_dance_01.png"];
sprite.position = ccp( size.width/2, size.height/2);
sprite.anchorPoint = ccp(0.5f, 0.5f);

// Create array for the animation frames
NSMutableArray *animFrames = [NSMutableArray array];
for(int i = 0; i < 14; i++) {
    CCSpriteFrame *frame = [cache spriteFrameByName:[NSString stringWithFormat:@"grossini_dance_%02d.png",(i+1)]];
    [animFrames addObject:frame];
}

// Convert the array into animation
CCAnimation *animation = [CCAnimation animationWithFrames:animFrames];

// Run the sprite with the created animation and display it by adding it to the scene
[sprite runAction:[CCRepeatForever actionWithAction: [CCAnimate actionWithDuration:2.8f animation:animation restoreOriginalFrame:NO] ]];
[self addChild:sprite z:0];

After all, don’t forget to deallocate the resources loaded in cache in function dealloc.

// Deallocate the resource in cache
CCSpriteFrameCache *cache = [CCSpriteFrameCache sharedSpriteFrameCache];
[cache removeSpriteFramesFromFile:@"animations/grossini.plist"];

Finally, this is a screenshot. Enjoy. XD

Usually while we extract information from other websites, character encoding might not correct. For example, j-jis.com is encoded with Shift-JIS. Therefore if your MySQL charset is UTF-8, it causes incorrect information. To handle the changing of character encoding, we can use iconv in PHP.

$url = "http://j-jis.com/";
$html = file_get_contents($url);
$html = preg_replace("/rn|n|t/", "", $html); //remove unwanted characters
$html = iconv("Shift_JIS","UTF-8",$html); //convert encoding
echo $html;

Json has been an efficient way to handle information and message exchanges in web programming. For example, I usually use PHP to connect MySQL and retrieve information, then display as Json. So a webpage can “AJAX” the displayed Json to create a dynamic view on itself. However, while the information involves unicode characters, PHP turn them into unreadable codes. After google, I found the following is the best way to solve the problem.

$string = '你好嗎';
echo json_encode($string); //Output "u4f60u597du55ce"
echo preg_replace("#u([0-9a-f]+)#ie", "iconv('UCS-2', 'UTF-8', pack('H4', '1'))", json_encode($string)); // Output "你好嗎"
%d bloggers like this: