Nov 29, 2012

How to Hide the Share Buttons of Blogger

Posted Nov 29, 2012
If you are using third-party sharing buttons such as Add This, you'll notice that the default share button of Blogger is left behind:


Fortunately, removing this is very easy. You just need to find where the setting is:
  1. Go to Layout Setting of Blogger


      
  2. Click the Edit link


     
  3. Untick Show Share Buttons option in the pop-up setting

Congratulations, your default share buttons are now hidden from view. 

Nov 27, 2012

SVN Revert a file to a Previous Version

Posted Nov 27, 2012
svn merge -c -[revision number] [file]

e.g.
svn merge -c -80 Classes/MyClass.m
80 is the revision number

Or if you want your entire revert your workspace:
svn merge -c -80 .


Nov 25, 2012

Node JS - Listen to External IP Address

Posted Nov 25, 2012
I wanted to try my local server in an iPad device and when I accessed its external port (192.168.0.24) in our intranet, it's not working. At first I changed the listen address from 127.0.0.1 to 192.168.0.24 and it worked, the problem was I cannot access http://localhost:3000 after. In addition, this approach of hardcoding the address is not an acceptable solution in the long run; there must be another way.

How to make your node js server listen to external ip

The fix is easy but not very intuitive. Just change the listen address from 127.0.0.1 to 0.0.0.0

I encountered a minor hiccup: I stored the address in a global variable and used it in a special function that accessed my own server. So my function was trying to access http://0.0.0.0:3000/... and it wouldn't work this way. So I just retained the 127.0.0.1 for my special functions.

I wonder why node js decided to implement it this way (or I'm not sure if it's Express js that's the culprit here). Why not just listen to all available IP Addresses when you specify 127.0.0.1? Maybe it's a security issue; I don't know.

[Update 18-Feb-2013] As "Reality Check" pointed out, NodeJS can listen to any IP address if you don't specify the host parameter. It's right here in NodeJs API:


server.listen(port, [hostname], [backlog], [callback])
Begin accepting connections on the specified port and hostname. If the hostname is omitted, the server will accept connections directed to any IPv4 address (INADDR_ANY).

Nov 15, 2012

Change the Back button Title in iOS UINavigation

Posted Nov 15, 2012

I thought it was straightforward to alter the title of the back bar button item. Turns out you need to define the entire back bar button item in the calling screen.

In the calling controller (meaning, the parent controller where you will push the new controller), add this in viewdidload:


self.navigationItem.backBarButtonItem =  [[[UIBarButtonItem alloc] initWithTitle:@"Custom Back Title"
                                    style:UIBarButtonItemStyleBordered
                                   target:nil
                                   action:nil] autorelease];


My mistake was I keep changing the backBarButtonItem of the new controller! Sheesh, Apple.

Nov 11, 2012

Chrome reloads sprite image on CSS image hover

Posted Nov 11, 2012
The image flickers on hover in Google Chrome when I have the following code:
#MAIN_MENU a.foodMenu {
 background: #000 url('../images/home_icons.jpg') -525px -176px no-repeat;
}

#MAIN_MENU a.foodMenu:hover {
 background: #000 url('../images/home_icons.jpg') -525px 0  no-repeat;
}

It seemed that my image was not preloaded fully so I tried preloading the image using javascript or css but to no avail. Found out that the problem is not in the preloading of image, it's the css definition. Apparently, Google Chrome thoughts it needs to reload the image even if you are using the same one.

The solution:
#MAIN_MENU a.foodMenu:hover {
 background-position: -525px 0;
}

Do not use background property to re-define the hover. Use background-position only to re-position the sprite. That's it!

Nov 10, 2012

Node.js: exports vs module.exports

Posted Nov 10, 2012
If you've been using node.js, you're probably familiar with the following scenario:

book.js:
exports.title = 'The Alchemist'

reader.js:
var book = require('./book');
console.log(book.title); // prints "The Alchemist" to console

In the above, "exports" allows us to call the property "title" of book.js. However, this approach always requires us to define and call a method or property. The object returned by "require('./book')" is the exports object which is created by the node.js framework but what if we want our own custom object returned?


This when "module.exports" becomes useful:

book.js:
module.exports = 'The Alchemist';

reader.js:
var book = require('./book');
console.log(book); // prints "The Alchemist" to console

In the above, notice that we don't need to call any method of book to be able to use it. In some cases, module.exports may be more convenient. In Express js, I use this approach to modularize my routes.

Nov 8, 2012

Use Node.js 0.8.14 or any custom version in Openshift

Posted Nov 8, 2012
It's relatively easy to set-up a different version of node js in Openshift:

1. rhc app create -a nodeapp -t nodejs-0.6
-- you can add "-s" to make the app scalable e.g. rhc app create -a nodeapp -t nodejs-0.6 -s

2.
cd nodeapp
git remote add upstream -m master git://github.com/openshift/nodejs-custom-version-openshift.git
git pull -s recursive -X theirs upstream master

3. Edit .openshift/markers/NODEJS_VERSION and specify the version you want, e.g. 0.8.14

4. Commit then git push

That's it! Happy coding!

[Updated March 2013] Created a Swig, Mongoose, Passport, Zurb Foundation and Node JS 0.10.1 package in github for OpenShift. I confirm that OpenShift works with Node JS 0.10.1

> rhc app create -a nodeapp -t nodejs-0.6

> rhc cartridge add mongodb-2.2 --app nodeapp

> cd nodeapp
> git remote add upstream -m master https://github.com/mannyvergel/node-swig-openshift-quickstart.git

> git pull -s recursive -X theirs upstream master

-- Edit .openshift/markers/NODEJS_VERSION commit then git push

Nov 6, 2012

[Solved] iOS didrotatefrominterfaceorientation is not called

Posted Nov 6, 2012
There are cases that did rotate method (didRotateFromInterfaceOrientation:) of a view controller is not triggered. A workaround is to manually call it from you main view controller, but if you don't have time, an easier fix is to use notifications:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];

Place the above in your controllers view will appear, and don't forget to unregister it in view did disappear.

- (void)didRotate:(NSNotification *)notification {
  //do your post-rotation logic here

}