Tuesday, May 31, 2011

Deep Copy in JS

Note: For those unfamiliar with the convention eval(uneval(_obj_)), this simply clones _obj_. It is cleaner than traversing each element of _obj_ and it will always be true that uneval(eval(uneval(x))) == uneval(x) and eval(uneval(x)) == deep_copy_of_x . The actual method uneval(_obj_) is a Spidermonkey specific (as of 1.7) extension that is not part of ECMAScript.

From Introduction to CouchDB Views

Monday, May 30, 2011

Setting up a Mac

As someone who came from a Windows + Linux background, setting up and using a mac was an irritating experience.

List of stuff I had to setup:
Other "stuff": CouchDB (using brew), MySQL

Fortunately, OS X comes with zsh, apache, mysql

movw $0x1f01,0xb8000; hlt

Was checking out the cool blog title here...

Sunday, May 29, 2011

Access Virtualbox guest via ssh

Apparently, it is possible to access a Virtualbox guest machine running sshd via ssh from the host machine.

Using PCnet-FAST III (NAT) as network adapter,

On the host machine: (where [guest] is the name of your guest machine.

$ VBoxManage setextradata [guest] "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222
$ VBoxManage setextradata [guest] "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
$ VBoxManage setextradata [guest] "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP

To delete an entry, set the value to an empty string.

Re/Boot your guest machine.

On your host machine:

$ ssh -l [user]@localhost -p 2222

Updated Vim Settings

Here's my vim settings.

Wednesday, May 18, 2011

Optimizations on ACM Timus

Some tricks I use on http://acm.timus.ru

Note: ACM Timus uses MS VCPP compiler, which differs from g++.

1. c++ is much much more efficient than java.
2. Use short/char instead of int whenever possible (to save memory), esp for arrays. Of course, there is a potential speed / memory trade off here since 4 byte ints register-size, but it doesn't seem to be issue on ACM Timus.
3. When memory is an issue, use stdio instead of iostream.
4. Using iostream may be "faster" than stdio?
5. "Implicit" stack overflow solution:
Use #pragma comment(linker, "/STACK:16777216")
6. Struct packing (for arrays) may not be memory efficient.
7. STL saves coding time.
8. Useful: #define FOR(i,n) for(i=0;i<(n);i++)

Java Optimizations:
1. Many prints are slower than one single print.
2. Buffered Reader/Writer is faster than Scanner.