Node.js: Array looping with async

To be honest, Node.js based asynchronous pattern makes me sick! It can be the worst idea to combine synchronous based coding pattern you’ve learned since first year in computer school. One of very special case of this sickening pattern is to use array based iteration (which is by default, synchronous) to process your data each by each asynchronously and do something else afterwards. Imagine you get code like this :

// data = [{_id: "1", childData: "1"}, {id: "2", childData: "2"}, {id: "3", childData: "2"});
// sum = [{_id: "1", sum: 500}, {_id: "2", sum: 600}]{}, function(err, datas) {
    var count = 0;
    for(idx in datas) {
        // Do MongoDB's relation query somewhere else
        db.childData.findOne({_id: datas[idx].childData}, function(err, childData) {
            count += childData.sum;

    // Show data output

Read More

Deploying your Node.js application with OpenShift (Free-Plan)

Even wondering how to deploy your web-based Node.js application on internet? Sadly, I will tell to you that: You can’t do that inside your ordinary cpanel-ed web hosting because they mostly only support PHP. Yes, that very sad news because you can rent a web hosting as low as a buck per month.

So the solution is to deploy it inside a PAAS (Platform as a Service) provider which is one of Cloud Computing solution to deploy a web application with many kind of supported platform (such as Ruby, Python, Google Go, and even Java). Unlike ordinary cpanel based web hosting, your web doesn’t run inside shared machine with many other web application. But also unlike dedicated hosting, it doesn’t run your application in single physical machine because it run inside a sandboxed virtual machine which will isolated your application thus makes it not dependent each other.

There are some PAAS solution which provided by major company such as Google Apps Engine, Windows Azure (by Microsoft), OpenShift (by Redhat) and Amazon Web Service (a.k.a AWS). Some of them provided a free plan and all of them of course provided pay plan which unlike traditional web hosting, the plan is not only based on how much space you need but also how much the CPU power, network bandwidth you need to run your application.

Now in this post, I will tell you how to deploy your Node.js application inside Redhat’s OpenShift which has a free-plan (with maximum 3 application per account). Deploying Node.js application is very easy if you know how to make it easy.

Read More

RT3290 Bluetooth (rtbth) driver with Kernel >= 3.13 + PATCH!

NOTE Most of users here tell me that this doesn’t work (bluetooth detected and on, but no pairing or connection). There is a bug report still ongoing to resolve this issue.

In my previous post, I did compiled and installed this source coded driver from Ubuntu PPA without any hassle with my previous Ubuntu 12.04 LTS (Kernel 3.8.x). But after an-hour-long upgrade process to Ubuntu 14.04 LTS (with newer Kernel 3.13), I need to recompile (make clean; make) this driver but unfortunately it failed and I got this message :

/usr/src/rtbth-3.9.3/rtbth_core_bluez.c: In function ‘rtbt_hps_iface_init’:
/usr/src/rtbth-3.9.3/rtbth_core_bluez.c:404:13: warning: assignment from incompatible pointer type [enabled by default]
  hdev->send = rtbt_hci_dev_send;
/usr/src/rtbth-3.9.3/rtbth_core_bluez.c:406:6: error: ‘struct hci_dev’ has no member named ‘ioctl’
  hdev->ioctl = rtbt_hci_dev_ioctl;
/usr/src/rtbth-3.9.3/rtbth_core_bluez.c: At top level:
/usr/src/rtbth-3.9.3/rtbth_core_bluez.c:83:20: warning: ‘pkt_type_str’ defined but not used [-Wunused-variable]
 static const char *pkt_type_str[]=
make[2]: *** [/usr/src/rtbth-3.9.3/rtbth_core_bluez.o] Error 1
make[1]: *** [_module_/usr/src/rtbth-3.9.3] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-24-generic'
make: *** [all] Error 2

Read More

CodeIgniter: Two action to prevent SQL Injection

In my previous post, I did explain to you about how to prevent XSS injection for your CodeIgniter Apps. And yet, for those who are novelty in web programming, I tell you the another kind of security hole in web programming which can be fatal because It can exposes your inner side of application’s database, it is SQL Injection.

Read More

CodeIgniter: Apply XSS filter as mandatory

If you are kind of novelty in web programming, and you have no idea what the XSS is, now I tell you what it is : “It is one kind of web application security hole that make use of unsanitized input so the intruder can input some Javascript/HTML in it”. And is it big deal? Yes, of course, because if they can do that, The malicious user input will be interpreted as real Javascript/HTML tag and therefore it will be processed/executed when it is printed.

Thankfully, CodeIgniter as one of PHP Application Framework which still gaining user base has a capability to deal with it. It has a XSS filtering mechanism which could be implemented to sanitized user input from GET/POST/Cookie data. If you want to use that, you just need to open CodeIgniter configuration file /application/config/config.php and edit this line :

$config['global_xss_filtering'] = TRUE;  # It is FALSE by default

And now if some adversary do inputting something like <script>alert(0);</script> inside of one of your application’s input, It will converted to be [removed]alert(0);[removed] so that it won’t be interpreted as a Javascript.

But remember, stick with using $this->input->post("variable") or $this->input->get("variable") when you are dealing with user input. Forget about that thing you learnt in first-time PHP class ($_POST[] or $_GET[]).

Vim Distribution: Complete ready-to-use Vim for you, fellow developer..

Vim is actually very nice text editor for all kind of software developer who write their code into a text file. Coding a software is not all about using that fancy IDE with drag-and-drop and click-click feature, real developer use text editor to code even with the simplest editor like Notepad.

Read More

Node.js 101: #2 The Basic of Node.js

Yesterday, I wrote my first post about Node.js explaining how to deal with its asynchronous non-blocking nature. Now in this post, let jump inside and learn how to code in Node.js. I won’t explain to you about the basic coding (such as sequence, branching and looping) because it is just as same as Javascript language that you know before.

Read More

dnode: Object oriented RPC with Node.js

Node.js has dozen number of library for everything you need to do a network and web application programming. One of old-school style of network or distributed system program is the use of Remote Procedure Call (RPC) mechanism which provided capability for the client to transparently call a function or modify an object inside the server remotely.

Read More

Node.js 101: #1 Introducing Node.js: Blocking vs Asynchronous Non-Blocking

Node.js is one of programming language which become more popular today, especially in the era of Cloud Computing where all of your stuff are saved in a cloud and people can easily reaching (or accessing) the cloud to take or put something in it. It still gaining more programmer who are attracted with its simplicity and capability for scalable based network programming.

Read More