Saturday, March 5, 2011

wireshark no network interface issue

wireshark is one of the best tool to deep network analysis. But due to the permission issue on BPF devices on Mac OSX (by default only root can read and write BPF devices), you won't see network interfaces in wireshare on Mac ;-(

There are two ways to fix:

- run sudo chown <your_user_id> /dev/bpf* on command line before you start wireshark, you will need to do it again after reboot

- add a startup script to fix this permanently (see instructions that comes with wireshark, D&D Utilities/ChmodBPF directory in the installation package into /Library/StartupItems
. You can adjust the script for your needs as well, for details, see the documentation that comes with wireshare.

Saturday, February 26, 2011

node.js hosting in Amazon EC2

node.js has rapid growth and there are so many hosting services available. Ryan maintains a long list of providers on github already and new ones like NodeFu keeps coming out every day. I have personally tried two managed hosting services duostack and JSApp.US, both are very easy to set up and use. The only drawback is that they pose limitations on installed modules, etc.

Amazon is offering 1 year free trial for its cloud services, so called "AWS Free Usage Tier". I decided to give it a try and set up an EC2 instance for node.js.

The whole process is not quite user friendly (not as friendly as the shopping experience on Amazon). There are quite several choices for the image to choose. My first attempt with a SuSE 64bit image also got permission issues when I install gcc somehow. Finally, from the Web search results, I found Mike Leach's step-by-step guide "Installing node.js on Amazon EC2", which is really helpful. Jim Smith's blog post added a nginx as the front end, a nice addition since node.js is not multi-threading out of box.

Some minor differences when I followed Mike's steps:
  • instead of ssh to the vm using ec2-user@ec2-public-dns, I had to use ec2-user@<address you can find in AWS management console by right clicking on the instance and then clicking connect>, note that the instructions there told you to ssh as root@<address>, but it did not work for me, saying I had to use ec2-user@
  • instead of --without-ssl option to ./configure, I added openssl and openssl-devel
  • I did node and npm installation using the "node-and-npm-in-30-seconds.sh" script from this gist mentioned in the Joyeur post "Installing Node and npm"

Saturday, February 12, 2011

handy tutorials

Just found several handy tutorials/references that could quickly refresh your knowledge about the tools and get work done easily.


Again, reading a lot is not as useful as coding a lot. But if you don't use it for day-to-day work, you might easily forget many tricks. So, some quick references are handy in this situation to bring you quickly up to speed.

Saturday, February 5, 2011

what does "new" do in JavaScript

Today, a colleague asked about exactly what is the difference between using "new" and calling the function directly. Only thing I can think of is the meaning for "this" inside the function. With "new", this means the object being created, but without "new", this means the global object, either window or something else. And I am also not clear what exactly happens behind the scene.

So, did some search and found some good readings that explains this topic fairly clearly. Lots of related answers from Stack Overflow is also quite helpful:
Here is a good article that tests your understanding of "new" keyword ;-)

Now, whether or not you should use "new" is another question:

Using "new" to instantiate a class has both pros (great performance) and cons (can cause nightmare if you forget to use new). Many people including Douglas Crockford discourages the use of new. A module pattern is a more preferable way. John Resig also has a simple solution to avoid using new directly without much performance sacrifice.

Sunday, December 5, 2010

Hack ASUS RT-N16 to enable NAS, media server, offline BT/emule, etc.


ASUS RT-N16 is the most affordable and versatile wireless router out there. I was previously looking for a NAS solution and then found that this router has 2 USB ports that could turn a printer into network printer and an external USB hard drive into a network storage.

The default firmware works ok so far. What I did is first configure it and then upgrade to the latest firmware version from ASUS website. UPnP and Samba file sharing worked fine out of box.

But after doing some online search, to really unleash the real power of this router, we need to install third-party firmware such as Tomato (it actually needs Tomato variants that support USB such as Tomato USB) and DD-WRT.

There are also several Tomato variants from Taiwan and mainland China: Tomato DualWAN, Tomato Pandora (supported routers) that supports web-based tools such as Chinese Web interface, BT, file system access, etc. I also found a Taiwan forum that discusses these variants, quite cool actually.

Searching on Tomato USB site gives several tutorials, but this one recommended by a colleague seems to be most straightforward and I am going to try it out now ;-)

Update:

The whole processing following the above tutorial went like a breeze. The only thing (not really an issue) that I encountered is that the restoration tool got stuck at 33% for quite a while and then gave a scary error message. But then I tested and the router is actually already running Tomato. So, simply ignore that error!

Note that you need to enable the USB option to get your external USB hard disk working. Here is an article that walks you through setting up a poor man's NAS with more detailed settings and controls. He also did some benchmark on a USB flash drive and found out that the flash drive has a better performance attached to the router than attached to the windows computer, unbelievable...

So, the next step will be to install Optware and get a lot of interesting toys (amule, transmission, unix tools, web servers, vpn, asterisk voip pbx, etc.) on it! Also heard there is another better UPnP solution that does transcoding for iOS devices (iPhone/iPad has many UPnP apps such as PlugPlayer, Apple TV supports XBMC), haha...

Wednesday, December 1, 2010

quiz time!

If you are confident about your JavaScript knowledge, try out these quizzes, it just made my brain stop working...
Now, if you feel how twisted/unreasonable/difficult/loose JavaScript syntax is, you are not alone.

Several good readings that might help to clear things a bit:
It is interesting that a variable can be declared after it is being used because the engine will hoist the variable declarations to the top of execution context.  Also interesting to see that the engine breaks "var i = 1" into declaration part "var i;" and initialization part "i = 1;", and move the declaration to the top.

Another interesting note is that function declaration overrides a variable declaration with the same name, but cannot override the variable declaration+initialization.
Really a comprehensive explanation about how execution context, scope, variable attributes, etc. work in JavaScript. Now, finally I understand the difference between variable declaration+initialization (cannot be deleted) and undeclared assignment (can be deleted) because of the former one has DontDelete flag and the latter one does not.

After reading this article, it is now apparent why the function declaration has strange override behavior for the variable with a same name. The variable declaration+initialization gets a DontDelete flag and thus cannot be overridden.
This one explained what is function declaration, function expression and named function expression and bugs handling named function expression in various JavaScript engines. One note is that for the named function expression, the name/identifier can only be accessed in its function body.
The ultimate reference for underlying mechanisms of JavaScript.

Monday, November 22, 2010

what this means in JavaScript

As someone new to JavaScript programming, there are many language features that are so uncomfortable. What *this* really means and referring to is one of the pains.

Finally, after reading some nice articles, I think I start to get the idea: it basically means the context/scope the function is called and can change at runtime.

Two great articles that explains this clearly: