Archive for December, 2007

My brother thinks he’s a chicken
December 22, 2007

“… I thought of that old joke, y’know, the, this… this guy goes to a psychiatrist and says, “Doc, uh, my brother’s crazy; he thinks he’s a chicken.” And, uh, the doctor says, “Well, why don’t you turn him in?” The guy says, “I would, but I need the eggs…”
— Annie Hall (1977) by Woddy [...]

Python Safe Calculator
December 17, 2007

Web-Safe Arithmetic Expressions Evaluator

import math
import re

whitelist = ‘|’.join(
# oprators, digits
['-', '\+', '/', '\\', '\*', '\^', '\*\*', '\(', '\)', '\d+']
# functions of math module (ex. __xxx__)
+ [f for f in dir(math) if f[:2] != ‘__’])

valid = lambda exp: re.match(whitelist, exp)

>>> [...]

Startup Entrepreneur?
December 16, 2007

First they ignore you.
Then they laugh at you.
Then they fight you.
Then you win.
MK Gandhi

Fibonacci, Generators and Python
December 16, 2007

Python is so beautiful and elegant
See this:
def fib():
a, b = 0, 1
while 1:
yield b
a, b = b, a+b

if __name__ == ‘__main__’:
f = fib()
for [...]

Accumulator Generator
December 13, 2007

Revenge of the Nerds yielded a collection of canonical solutions to the same problem in a number of languages.

The problem: Write a function foo that takes a number n and returns a function that takes a number i, and returns n incremented by i.

Note: (a) that’s number, not integer, (b) that’s incremented by, not plus.

Googlereader, Heaven’t you heard of firebug?
December 10, 2007

… and I thought this method of raising errors belongs to the far past of web development…