July 25th, 2006

  • evan

cool programming problem

Here's a description of the problem I spent a lot of time (way too much, really) on. I enjoyed both the programming challenge and the story that accompanied it.

For background, remember that earlier we built a virtual machine and were now running an image on it, and it had dropped you into a Unix-like system.

Collapse )
  • evan

s-expression parser

Here's a slightly-cleaned-up version of the s-expression parser I used.
data SExp = A String | S [SExp] deriving Show

psexp = liftM S $ parens ((psexp <|> atom) `sepEndBy` spaces) where
  parens  = between (char '(') (char ')')
  atom    = liftM A (literal <|> quoted) where
    literal = many1 (lower <|> char '_')
    quoted  = do q; manyTill anyChar q where q = char '"'

No parser generator or lexer, just some function calls, and it reads almost how you'd describe parsing to another person ("a quoted string is a quote followed by a multiple characters up until a quote").

Here's a function that pretty-prints an SExp as a tree, with indents.
prettyP sexp = render (doc sexp) where
  doc (S (x:xs)) = hang (doc x) 2 $ vcat (map doc xs)
  doc (A string) = text string


The key to both of these is nice libraries.
  • evan

ljrb 0.3.0

ljrb 0.3.0: This release adds support for the "current_location" field and fetching friendofs in the same request as fetching friends. There's also a minor bugfix (entry == nil would raise an exception).

The Rubygem of this release has now grown to exactly 32768 bytes, so make sure you use at least 16 (unsigned) bits when mentioning it.
  • evan

ubuntu broken locales (cadt strikes again)

A while back I received a Chinese translation for LogJam. Tonight I got around to testing it, but discovered that the normal way to configure my locales had stopped working. CADT strikes again!*

Some background: To run a program in a different language, you need to have configured locales, which (to my not-really-understanding understanding) is a bunch of data files off in /usr/share somewhere. Typically, you edit /etc/locale.gen and then run locale-gen; or, if you wanna be fancy, it's dpkg-reconfigure locales and it'll give you a list of languages to check off for installation.

But on my system now, there is no /etc/locale.gen, though there mysteriously is a manpage for it. And the dpkg command just regenerates the English locales (all 15 of 'em, one for each dialect of English) without asking me anything.

After some poking and prodding -- everything you'll find on Google describes the same procedure I gave two paragraphs up -- I finally discovered Ubuntu bug #48573, where someone basically says "Um, this used to work and it broke." And the response is, "That is intentional. We now have a Totally New Way to configure this and it's nicely controllable via System→Administration→Language Support."

Unfortunately I don't have a System→Administration→Language Support, nor do I know where to get one. Hrmph.

* I'm not really too upset about this, as I can recognize there may have been good reasons to make the change. On the other hand, I am upset that it was broken in such a way that I can't track down the fix.