Backtick on iPhone!

Posted by lorne on February 22nd, 2009 — Posted in General

Keyboard layout that includes a backtick!

FlickrTidy

Posted by lorne on September 30th, 2007 — Posted in General

Some photos on Flickr have nothing but “awards” in the comments. These “awards” are little more than thinly veiled spam and there are few things more irritating than spam. Here’s an example.

Python Gotchas

Posted by lorne on September 4th, 2006 — Posted in General

I’m currently required to use Python for COMP312. Having come from doing nothing but Haskell and Prolog in COMP304 you can imagine my mind isn’t exactly bent around Python’s way of doing things. Here are a couple of traps I ran into

First off is expressions and lambda

>>> def p(x): print(x)
...
>>> f = lambda x:p(x)
>>> f(5)
5
>>> f = lambda x:print(x)
  File "<stdin>", line 1
    f = lambda x:print(x)
                     ^
SyntaxError: invalid syntax

You cannot put an expression in a lambda. What’s more there is no implicit return value in Python. There was a thread about this, for those of you with access to the MSCS forums. After that last post I wasn’t sure how to reply

Next up is scope

>>> def counter(x):
...     base = x
...     def inc():
...             oldbase = base
...             base = base + 1
...             return oldbase
...     return inc
...
>>> c = counter(5)
>>> c()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 4, in inc
UnboundLocalError: local variable 'base' referenced before assignment

“Oh, but that should happen as base shouldn’t leak into inc!”

>>> def counter(x):
...     base = x
...     def inc():
...             oldbase = base
...             return base
...     return inc
...
>>> c = counter(5)
>>> c()
5

Python is happy to read variables and mutate objects, but introducing assignment makes Python come up with a new variable for you. The obvious argument is that this counter should be a class. Perhaps true, but it still caught me out.

Short Code

Posted by lorne on June 21st, 2006 — Posted in General

One of the complaints I’ve heard about Haskell is that it makes your code shorter. I’m not quite sure how that’s a bad thing, but it occurred to me while looking at a algorithm I wrote in Ruby.

puts $_.chomp.gsub(/../) { |b| b.hex.to_s + "."}.chop

The algorithm takes an IP address compactly represented in hex and returns the dotted decimal form.

Parsec is wonderful! I’ve been using it for a tetrinet protocol decoder so that was the first thing on my mind.

main = do
  (h:_) <- getArgs
  case parse (count 4 hexbyte) "Arguments" h of
    Right r -> putStrLn $ tail $ concatMap (('.':) . show) r
    Left e -> fail $ "Invalid input\n" ++ (show e)

hexbyte :: Parser Int
hexbyte = count 2 hexDigit >>= return . read . ('0':) . ('x':)

Which seems fairly easy to follow and has some error reporting free from Parsec, but I figure a parser library might be overkill for this task.

Turning to more “raw” Haskell, mostly the useful functions in the Data.List library, gives

main = getArgs >>= putStrLn . concat . intersperse "." .
       map (show . readByte) .  unfoldr lf . head
       where
         readByte :: String -> Int
         readByte = read . ('0':) . ('x':)
         lf [] = Nothing
         lf t  = Just $ splitAt 2 t

They’re all following approximately the same algorithm of a mapping on every two characters. However the gsub(/../) { |b| … } appears to be a very compact notation which I have been unable to match.

Pros and Cons RSS

Posted by lorne on December 12th, 2005 — Posted in General

This is not some silly new product title, it is the announcement of an RSS feed.

Flickr

Posted by lorne on November 23rd, 2005 — Posted in General

After stealing a camera to take photos of tictacs for use with tic.t.ac.nz I decided to get myself a camera. Now armed with a Fuji FinePix E500 and a free Flickr account I’m ready for anything. The camera has joined the rest of the equipment that lives in my bag and my iBook is now equipped with iPhoto.

I do have a “camera” in my phone but it really is hopeless. As far as I’m aware, the argument goes “I want a camera in my phone so it’s always with me”. I intend to keep my real camera for this purpose, however some people seem to take this a little too far.

Of course, take a look at my photos

Flock

Posted by lorne on October 22nd, 2005 — Posted in General

Flock is a recently released “social” web browser derived from Firefox. For the social part, it offers posting to various blogs (including WordPress) with a built-in editor and del.icio.us for bookmarks. As everything these days has an RSS reader builtin, it’s not surprising this does also. The feature I like the most is a searchable history by way of CLucene. Typing in the search field gives a Spotlight like view of pages you have visited that contain that term.

It’s still in development and there are some obvious things that are missing, but definately something to keep an eye on.

And yes, this post was written with Flock.

Salient Released

Posted by lorne on October 5th, 2005 — Posted in General

The issue of Salient containing the article, temporarily prevented from distribution, has been released. I got my hands on a copy tonight and scanned it, just page one, page two and page one in colour if you so desire.

HTTP in Reverse

Posted by lorne on September 15th, 2005 — Posted in Linux

The design of pros.and.cons makes it difficult to easily track new changes. I’ve whipped up something to notify you when there are changes.

I used the phrase “notify you” as this is what took the most time to do. There is a notification management daemon running which broadcasts the messages generated by the pros.and.cons script. To get this working nicely over HTTP, the background request is made to a script that returns either when there is something to report, or a period of time has elapsed. Notice the typical chain of events would cause a notification to be sent, an instance of the client script to return and the result to be displayed, such that there is no wasteful polling.

Dolls

Posted by lorne on August 30th, 2005 — Posted in General

Eleanor Toland has been creating “dolls” with likeness to people she knows and including them in her blog posts. There was one I quite liked so I stole the pictures from it and put them up as splash pages. Then came more and I couldn’t resist, so far I’ve got fibonacci, lorne, donald and eleanor.

Here’s hoping for some more!