Saturday, March 13, 2010

First post of 2010

Just because I haven't done it in awhile.

Tuesday, August 4, 2009

Give me a function that given a line, describes the next

1
11
21
1211
111221
312211
13112221
1113213211


char* get_next_line(char* line)
{
char next_line[4096];
int next_line_ndx = 0;

char letter = line[0];
int num_letters = 0;

for (int i = 0; i < strlen(line); ++i)
{
if (letter != line[i+1])
{
next_line[next_line_ndx] = num_letters + '0';
next_line_ndx++;
next_line[next_line_ndx] = letter;
next_line_ndx++;
next_line[next_line_ndx] = 0;

letter = line[i+1];
num_letters = 0;
}
else
{
num_letters++;
}
}

return next_line;
}

Wednesday, July 29, 2009

breadth first search of binary tree (w/o the formatting)

7
/ \
1 2
/ \ /
0 3 4
\
2

7
1 2
0 3 4
2



def traverse_tree(node):
q = []
last_level = 0
current_level = 0
q.append([node, current_level])

while len(q) > 0:
node, current_level = q.pop()

if current_level != last_level:
last_level = current_level
print "\n"
print node + " "

left_child = node.left
right_child = node.right

if left_child not NULL:
q.append([left_child, current_level + 1])

if right_child not NULL:
q.append([right_child, current_level + 1])

Monday, October 20, 2008

MySQL restart on Mac OS X

This is the simplest way to restart the server on Mac OSX that I found

my-computer:~ me$ mysqladmin -uroot -p shutdown
Enter password:
my-computer:~ me$ sudo mysqld_safe
Starting mysqld daemon with databases from /sw/var/mysql

Thursday, October 16, 2008

Voted

I voted so I have the right to complain.

Wednesday, October 8, 2008

MySQL Python API

If you try to install the python API for MySQL on Leopard, and receive the following message:

lipo: can't open input file: /var/tmp//ccDsRjet.out (No such file or directory)

make sure you check out this.