Posts Tagged ‘linkedin’

Tracking down potential bug in PyISAPIe

March 27, 2012 Leave a comment

Brushing up on my C skills…

Categories: C, Programming, Python Tags:

Take an encyclopedia with you wherever you go

March 22, 2012 Leave a comment

I’m working on a new project:  Putting 45,000 Wikipedia articles on a USB stick for offline use, e.g. for doing research while traveling on a plane, train, bus or in the car (preferably not while driving).

It’s for sale now at – check it out!

Categories: Links Tags: ,

Shenandoah National Park Oral History Collection

March 13, 2012 Leave a comment

A project I’ve worked on over the last few years is now online at  It is a collection of oral history recordings and transcripts, delivered through a custom interface built on MDID3.

See the official announcement at

Categories: Programming Tags:

Udacity CS373 Localization Problem

March 1, 2012 Leave a comment

I’m taking the Udacity CS373 Programming a Robotic Car class.  Below is my solution to the localization homework problem in unit 1 that was due yesterday.  Note that this is not the complete program, just the homework portion.

world_width = len(colors[0])
world_height = len(colors)

p = [[1. / (world_width * world_height)] * world_width
     for i in range(world_height)]

def sense(p, Z):
    q = [
                pcol * (sensor_right if scol == Z else (1 - sensor_right))
                for pcol, scol in zip(prow, crow)
            for prow, crow in zip(p, colors)
    norm = sum(sum(row) for row in q)
    return [[col / norm for col in row] for row in q]

def move(p, motion):
    ym, xm = motion
    return [
                p_move * p[(y - ym) % world_height][(x - xm) % world_width]
                + (1 - p_move) * p[y][x]
                for x in range(world_width)
            for y in range(world_height)

for me, mo in zip(measurements, motions):
    p = move(p, mo)
    p = sense(p, me)

Instead of looping, I make use of list comprehensions, which I think is a cleaner solution.

Categories: Programming, Python Tags: , ,

Lazy objects in Django

February 15, 2012 1 comment

Working on one of my Django projects, I created a new context processor to populate some template context variables.  One of them was a list of values pulled from the database that was only used on a few pages, so I tried to wrap it in a SimpleLazyObject:

from django.utils.functional import SimpleLazyObject
def current_presentation(request):
    presentation = SimpleLazyObject(lambda: fetch_current_presentation(request.user))
    presentation_records = SimpleLazyObject(lambda: list(presentation.items.values_list('record_id', flat=True).distinct()))
    return {
     'current_presentation': presentation,
     'current_presentation_records': presentation_records,

That unfortunately does not work:

TemplateSyntaxError: Caught TypeError while rendering: argument of type 'SimpleLazyObject' is not iterable

The problem is that the SimpleLazyObject wrapper does not implement an __iter__ method, so a wrapped object that is iterable loses that property.

The fix: a new subclass of SimpleLazyObject:

class IterableLazyObject(SimpleLazyObject):
    def __iter__(self):
        if self._wrapped is None: self._setup()
        return self._wrapped.__iter__()


Categories: Programming, Python Tags:

Hacker Olympics Puzzle, Part 2

February 14, 2012 Leave a comment

I am trying to teach myself Erlang, so I gave the Hacker Olympics Puzzle another try in a complete new (to me) language.

Here are the functions that do the work, the main program with the code are in a seperate file.  Everything is in a repository on github.


decode(Code) -> convert(process(Code)).

process(Code)                            -> process(Code, [], []).
process([], Unique, _)                   -> Unique;
process([X, Y|Code], Unique, Duplicates) ->
    Pair = {X, Y},
    IsDuplicate = lists:member(Pair, Duplicates),
    IsUnique = lists:member(Pair, Unique),
    process_pair(Pair, IsDuplicate, IsUnique, Code, Unique, Duplicates).

process_pair(_, true, _, Code, Unique, Duplicates) ->
    process(Code, Unique, Duplicates);
process_pair(Pair, _, true, Code, Unique, Duplicates) ->
    process(Code, lists:delete(Pair, Unique), [Pair|Duplicates]);
process_pair(Pair, _, _, Code, Unique, Duplicates) ->
    process(Code, [Pair|Unique], Duplicates).

convert(List)               -> convert(List, []).
convert([], Result)         -> lists:concat(Result);
convert([{X, Y}|T], Result) -> convert(T, [cchar(X) + cchar(Y)|Result]).

cchar(C)           -> cchar(C, 0, "qwertyuiop").
cchar(C, I, [C|_]) -> I;
cchar(C, I, [_|T]) -> cchar(C, I + 1, T).
Categories: Erlang, Programming Tags:

Hacker Olympics Puzzle

February 8, 2012 1 comment

Last night at the Shenandoah Ruby User Group meeting everybody gave this programming puzzle a shot.  Only after the meeting did I make the connection to regular expressions and was able to cut my Python code down to a tweetable format (excluding the input data).

s = "iirytroyppytpeppowuiyoiuypipiyuyotyoiwiytorouqyiepyirueuiprpptwyiroqwtuyipourrrourorwipowiorutpwtwruuioquteorioriyutwqyyprptuqqquuituyywyuoewtrppqwrtiiruirpwyptpuoyyoeyerpqiotuieripurouwuwyuwrworowitoepoypeipeypiireeorrwripuuteoitpuutturruwiyryeetyrioweytueqrrrtotrpiqetoyepoipiwrwpppiritupwipruooiepoweypiuwrqywuuwyiroqpqpruioopuiuerputpwwuuiqwpiroewrtwiqerteoyeqtutwoeoipioiuqiiiouuoqtuuwtuwiiqwppqitywuqpuutrqiyoeuuutwrwtoqrqyoeyoiporuuioiwryoeruypreprqroiyuqwtuyoytoerwqryeeripryieypiwqirtriurueypiuyuypriuiwptywppupoioyrewooytreteeriiwroietuwypieeeeeqpiiiwrirtppoeyiwpooyyporpruwuoriiyowuytiwpwpryeywotoyirqypyypoeptiuwwoyprquoetepptorwiewprpiywwtuieeiweytrrwiqtwotioryoiptyyyuriiqiyroeeiqepwteuwptpruuypipieuoiiuuweeuryuuowporrooyywyyrryriqyirooitirueruptotpryoqtipippyptiurwyiryooywtryyuurtrutwqiqiiiqwouyeooueoturuowiuwrtruwwiupwopwweoo"
import re
while s:
 if n<1:
  print sum("qwertyuiop".find(l) for l in s[:2]),