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

Pydev: The Best Python IDE

While I don’t usually advertise, I love eclipse for all of its feature rich implementations of language specific IDE’s. Among those is Pydev, a complete first class IDE for Python.
Recently, Pydev just hit version 1.6.0 (Congratulations!) with the following new features and oddities:

Release 1.6.0

o Code-completion added to the debug console
o Entries in the debug console are evaluated on a line-by-line basis (previously an empty line was needed)
o Threads started with thread.start_new_thread are now properly traced in the debugger
o Added method -- pydevd.set_pm_excepthook() -- which clients may use to debug uncaught exceptions
o Printing exception when unable to connect in the debugger
o Interactive console may be created using the eclipse vm (which may be used for experimenting with Eclipse)
o Apply patch working (Fixed NPE when opening compare editor in a dialog)
o Added compatibility to Aptana Studio 3 (Beta) -- release from July 12th

http://pydev.org/

Among others, Pydev also integrates gracefully with Jython and IronPython (that’s right, it’s a competitor of visual studio), contains templates and tools for AppEngine and Django projects, inline unit testing, an interactive console with autocomplete, ability to refactor portions of your code, autoimport and dependency resolution (even for unimported modules), a nice set of embeded debugging tools, and of course, syntax coloring.

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

Python: Self references in List comprehension

One of the great abilities in Python that is copied over from Haskell is the ability to construct lists from other lists or iterators inline. This is of course limiting in certain cases where self references are necessary. For example, if we need to check whether a list is unique, we would have to construct another list to hold reference to all objects that have already been iterated over. This is where one of Python’s uglier “features” comes into play.

Python allows a list to reference itself during list comprehension by keeping track of the object, and all subsequent levels of iteration, in local scope:

#Single step removal of duplicate values.

>>> (lambda xs: [x for x in xs if x not in locals()['_[1]']])([1,2,2,3,4,4,5,5,5,6])
[1, 2, 3, 4, 5, 6]

But be warned: If you do this regularly, the python gods will hunt you down and torture you.

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

strcpy() implementation in C/C++

One of our ubiquitous C functions can be rather easily recreated via C:

char* strcpy(char* other, char* self){
    while (*self) *other++=*self++;
    *other = '\0';
}

Note that C strings are null terminating, hence we create a simple while loop in order to copy everything before we reach the null \0 character. In order to follow convention and meet C’s expectation, we manually add a null character at the end of the string.

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