Category Archives: Snippets

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

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

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…

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…

Posted in Blog, Lua, Programming, Snippets | 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(?)

Posted in Blog, Lua, Programming, Snippets | Tagged , , , , , , | 1 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,…

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…

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

Python Tip: Copying an object

One of the several “features” of python that often land beginners head over feet with their faces in the mud is the distinction between references and copies. Say we have the following list a:

a = [1,3,5,7,9,11]

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

Brain Teaser: Multiply by 6

How do I go about multiplying a real number n by 6 in python without using the * or the + operators?

Solution:

x6 = lambda n: (n<<3) - n - n

Rationale:

n

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