Category Archives: Programming

SQL Select with Write Lock

SQL transaction is usually used when we want to make database changes in a consistent state. When inserting/updating row in a transaction, a write lock will be held by the transaction so other transaction cannot do update at the same … Continue reading

Posted in Programming | Tagged , , , | Leave a comment

A Little Misconception about Promise (nodeJS)

Consider the following code var Promise = require(‘bluebird’); function f(x){ return Promise.try(function(){ console.log(“start ” + x); return Promise.delay(500); }) .then(function(){ console.log(“finish ” + x); }); } var promises = []; promises.push(f(1)); promises.push(f(2)); Promise.each(promises, function(){ return f; }); Expected result: start … Continue reading

Posted in Programming | Tagged , | 2 Comments

Parallel asynchronous functions with NodeJS promise

Long time since I last wrote a post. So recently I’ve been doing NodeJS and meets a cool feature: Promise. Promise is a way to make asynchronous callback look like serial, so instead of writing doSomething(function(err,obj){ if (err) … … … Continue reading

Posted in Programming | Tagged , , , , | Leave a comment

[ios] Drawing unicode string in CGContext

There’s one big, big defect in CGContextShowText function. It only works for ASCII characters. There’s actually another way to draw in CGContext using NSString drawInRect: method, but it doesn’t work in my case because I need to calculate all the … Continue reading

Posted in Programming | Tagged , , , , , | Leave a comment

[iOS] Automatic Reference Counting and cross reference

Even with Automatic Reference Counting (ARC) feature in iOS 5, cross reference between objects should still be treated with care. A cross reference is where 2 or more objects are referencing each other, making circular reference. In which case, the … Continue reading

Posted in Programming | Tagged , , , , | Leave a comment

Easy comment-uncomment with 1 character

This is commented. /* do_something(); //*/ This is not. //* do_something(); //*/ Got this from a friend who got this from a friend who got this from a friend who…

Posted in Programming, Tips | Tagged , , | Leave a comment

[iOS] Pointer to Block Pointer

iOS block programming feature is pretty cool, it makes asynchronous programming easier. This time I want to talk about block pointer. A block pointer is a type of variable that we can use to refer to a block, for example … Continue reading

Posted in Programming | Tagged , , , , , | Leave a comment