College

Cornell is a blast and I’m too busy lately to blog. I’ll come back into the techy world as soon as I can find some time. Take care my fellow nerds :D

Posted in Blog, Miscellaneous | Leave a comment

How do you sort your cloths?

According to the massively credible spammers on Facebook, the following is a common question asked by Google interviewers to interviewees.

Imagine you have a closet full of shirts. It’s very difficult to find a shirt. What can you do to organize your shirts for easy retrieval?

Now I’m not suggesting that I’m looking to get a job with Google, that would be pretty awsome mind you, but I doubt that they would be interested in emotionally unstable (hey, I’m kinda mature… I guess?) 18 year olds. :/

In the midst of deliberating whether I should stack or hang them, I thought to myself, why not write a computer simulation? One thing led to another, and the result of a wasted evening yielded… well, something that’s pretty weird. (Albeit it is not at all useful)

Visualizing a computer Stooge Sorting 23 Shirts :D Note that you’ll need to scroll a lot to see the end result.

Stooge Sort Visualization of 23 shirts.

A little bit on stooge-sort, it is a sorting algorithm of not nlog(n), nor of n, nor even n^2, but of n^2.7 complexity.

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

Javascript Syntax Highlighted Editor in 1Kb

I’ve just written an edit in place syntax highlighter for Javascript. The cool thing about it is that it’s under 1Kb (1023 bytes to be exact xD). Here’s the code:

// Revised Edit-In-Place syntax editor still sits at 1023kb xD
(d=document).write('<style>#p,#d{text-shadow:0 0 20px #39E;top:0;left:0;white-space:pre;color:#756;width:100%;height:100%;padding:10px;border:none;line-height:20px;position:absolute;background:transparent;font:14px "Courier New"}#p{opacity:0.4}</style><div id="d">JS</div><textarea id="p"></textarea>');p=d[g="getElementById"]("p");n="length";function j(b,a){l=[];for(_ in a){i=0;$=a[_];for(m=b.match(a[_]);$.test(b);)l.push([$.lastIndex-m[i][n],m[i++][n],_])}l.sort(function(c,f){return c[0]+1/c[1]-f[0]-1/f[1]});h=0;z=[];for(_ in l){$=l[_];e=$[0]+$[1];if(!(e<=h)){z.push([h,$[0]-h,g],$);h=e}}z.push([h,b[n],g]);return z}p.onkeyup=function(){var b=d[g]("d"),a=p.value;t=j(a,{"#288;border-bottom:dashed 1px #ccc":/\/\/.*|\/\*(.|\n)+\*\//g,"#D24":/"[^"\n]*"|'[^'\n]*'/g,"#08c": /\b(else|switch|break|throw|case|catch|new|finally|null|try|const|for|continue| function|var|if|return|delete|while|do|with|in)(?!\w)/g});s="";for(i in t){y=t[i];s+="<span style='color:"+y[2]+"'>"+a[ss="substr"](y[0],y[1])+"</span>"}b.innerHTML=s}

To see the full unedited source code, go to http://gist.github.com/513014

EDIT: To see an online demo of the latest version, go to http://failboat.me/jpad.html

Posted in Blog, Programming, Snippets | Tagged , , , , | 6 Comments

Woohoo

Got myself a new Samsung Captivate :D

In other news:

(2) Computer programs that enable wireless telephone handsets to execute software applications, where circumvention is accomplished for the sole purpose of enabling interoperability of such applications, when they have been lawfully obtained, with computer programs on the telephone handset.
(3) Computer programs, in the form of firmware or software, that enable used wireless telephone handsets to connect to a wireless telecommunications network, when circumvention is initiated by the owner of the copy of the computer program solely in order to connect to a wireless telecommunications network and access to the network is authorized by the operator of the network.

Woohoo, it’s officially legal to root and jailbreak your smartphone now :D . This will come handy when you need to tether to an AT&T android.

Posted in Blog, Miscellaneous | Tagged , , , | Leave a comment

Rocket: A Lua Sqlite3 ORM manager

Relational databases are designed so that they can both store and describe data. Most programming level APIs do wonderful jobs of maintaining the former aspect. I mean, what ORM doesn’t automatically map the insert method to the so very generic INSERT (x,y,z)

However, the latter part is often omitted. If you want to write a schema that describes the relationship between a clan and a very generic user system, you will need to write a lot of glue code just to make sure that everything sticks together. And if you want to write another layer on top of that, well, the amount of effort is literally exponentially incremented every time that you want to extend your application.

There are a few libraries that do great jobs of automatically maintaining explicit relationships between different tables. At the top of this list is Django’s model system, a very extensible python web-based framework. Django lets the user describe data in forms of Python classes with fields as attributes. It’s very intuitive and it contains a great set of deferred query generation system that allows you to create lazy querysets.

Continue reading

Posted in Blog, Lua, Programming, Snippets | Tagged , , , , , , , | Leave a comment

See.lua – Documentation

See.lua – A Lua introspection library

	> see(string)

	.byte(?)            .char(?)            .dump(?)            .find(?)
	.format(?)          .gfind(?)           .gmatch(?)          .gsub(?)
	.join(self, table, ...)                 .len(?)
	.lower(?)           .match(?)           .rep(?)             .reverse(?)
	.sub(?)             .upper(?)

Lua is a wonderful little language that lets you do a lot of cool stuff. However it’s not very friendly to those of you who are more curious. For example, let’s say that we were just given a random library:

	> require "lanes"

and we want to see what is in the lanes library:

	> =lanes
	table: 00698298

Wait wait wait, what is it with all these numbers? All I wanted to do was look at what is inside the lanes table. Now there’s an easy solution for these types of situations:

	> see(lanes)
	.ABOUT[5]           ._M[9]              ._NAME              ._PACKAGE
	.gen(...)           .genatomic(linda, key, initial_val)     .genlock(linda, key,N)
	.linda()            .timer(linda, key, a, period)

	Metatable
	.

Download See.lua from http://failboat.me/2010/see-lua-introspecting-lua-objects/ or fork it at http://github.com/leegao/see.lua
Continue reading

Posted in Blog, Lua, Programming, Snippets | Tagged , , , | Leave a comment

How to fix the keyboard issues with Ubuntu Login

If you have installed Ubuntu 10.x on vmWare, you will find that the default keyboard configuration does not let you type anything into the login box. This is a big issue since Ubuntu requires that your root user has a password. In order to get around this issue, do the following:

#STEPS

Click the button on the bottom-right side of the screen and click on "Universal Access Preference".

Click to toggle the first option that says "Use on-screen keyboard" and click Close.

Now you will need to reboot your VM in order to see the keyboard.

That’s it, after the login screen your keyboard automagically starts working again…

Posted in Blog, Miscellaneous | Tagged , , , , , | Leave a comment

see.lua – Introspecting Lua objects

As via its python equivalent, see.lua takes in an object and prints out a list of its elements as well as metatable methods in readable text.

> require "see"

> s = see(string)
.byte(?)            .char(?)            .dump(?)            .find(?)
.format(?)          .gfind(?)           .gmatch(?)          .gsub(?)
.join(self, table, ...)                 .len(?)
.lower(?)           .match(?)           .rep(?)             .reverse(?)
.sub(?)             .upper(?)    

> see{1,2,3,4,5}
{1, 2, 3, 4, 5}

> see(see)
function(object, query)

> see()
@NIL	nil

> s.join()
@join
function(self, table, ...)

> x = {self = {1,2,3}, four = {1,2,3,5=4}, blargh = ""}
> setmetatable(x, {__call = function() end, __add = function() end, __concat = function() end})
> see(x)
.blargh             .four[4]            .self[3]
Metatable
+                   ()                  ..

You can get it at http://gist.github.com/486964 or the development branch at http://github.com/leegao/see.lua

Posted in Blog, Lua, Programming, Snippets | Tagged , , , , , , | 1 Comment