Android : flashing :: programming : ?

Your editor will confess that he still feels a certain childlike joy at the prospect of reflashing an expensive device that he depends on, possibly bricking it, then painfully restoring all of the settings and discovering all of the new bugs which have been added. It’s the sort of adrenaline experience that others, perhaps, seek through horror movies, bungee jumping, investing in equities, or PHP programming

Jonathan Corbet, The end of the road for the Nexus One, Linux Weekly News


iTunes feed extractor

The downside of Apple’s iPod/iPhone being so popular is that so many podcasts only publish iTunes links, instead of the more standard RSS/Atom feeds. And I know of OS X and Windows users who detest iTunes — imagine how Unix users feel!

Well, the feeds are still there, but hidden from plain sight — turns out, though, that if you pretend to be iTunes, you can actually trick the iTMS server into giving you the raw data. And with Python 2.6’s built-in support for Apple’s property lists, extracting the feed is a trivial matter.
Continue reading

Logic programming on the JVM

Just a quick post (the time is rather late) to note that my port of the Mini Kanren logic programming system to Scala is now available for download (and bug reports) on GitHub; for the scaladoc API documentation and a presentation discussing the porting effort, visit the project homepage.

It has an almost-complete numerical stack — the missing arithmetic relations are not coded yet because I was documenting and/or getting larger test cases to work — and likewise with list-processing support. The years-old stack overflow problem I initially attributed (when taking a programming language course, and having no time to debug thoroughly) to Java’s lack of TCO turns out to be fixable by some judicious call-by-name optimizations.

Having just discovered metalua and its macro goodness, I’d say that after bringing Kanren to the JVM, the next step would be to have a C-embeddable Kanren written in metalua. There might be some performance snags, though — the Scala port is currently about 3x slower than Mini Kanren running on Petite Chez Scheme.

Technorati Tags: , , , , , ,

OOP in Lua: abstract methods

I discovered Python’s delightful abc module (introduced in PEP 3119) a while back, and have been wondering how a similar functionality could be introduced to other dynamic languages (e.g. Lua and Ruby).

Being more familiar with the former, over the weekend I decided to try and write an equivalent module. Two problems came to mind:

  • Python uses an @abstractmethod decorator to mark an otherwise-normal function definition. While a decorator pattern can be used in Lua (though not a standard practice), this Python decorator works by setting an attribute in the function it decorates:

    funcobj.__isabstractmethod__ = True

    This is not an option in Lua, because functions don’t have individual metatables.

  • Python has a standard way of doing OOP, and the enforcement that an instantiated class does not contain any abstract method is done in the __new__ method of the ABCMeta metaclass. Contrast to Lua, where OOP is normally done in an ad-hoc manner — and even the LOOP library provides several OOP inheritance mechanisms.

The solution I adopted is delightfully simple: the abc module provides two functions: an amethod function that throws an exception no matter what arguments it is passed, and a verify function that takes a classname, and reflects on the members (using loop.cached.allmembers if possible, falling back to pairs if loop is not installed) and check if any of them is equal to amethod.

This works even on simple tables, though it shifts the responsibility a bit to the programmer: unit tests should be used to verify each created class. As a fallback, attempts to use the abstract methods will fail at runtime, but that’s taking dynamism a bit too far…

Still working out how to get the Pythonic behavior (instantiating a class with some abstract members should fail) when using LOOP. Meanwhile, try it out for yourself and make sure to file bug reports!

Technorati Tags: , , , , , , ,

[PYTHON] Find of the day: B+ Tree-based lists

I was looking at implementing Clojure’s persistent data structures on other languages — being able to assume that collections are immutable make writing concurrent programs much easier, since these collections can be shared without locking.

While looking if this has been done before, I came across a rejected Python Enhancement Proposal:

The common case for list operations is on small lists. The current array-based list implementation excels at small lists due to the strong locality of reference and infrequency of memory allocation operations. However, an array takes O(n) time to insert and delete elements, which can become problematic as the list gets large.

This PEP introduces a new data type, the BList, that has array-like and tree-like aspects. It enjoys the same good performance on small lists as the existing array-based implementation, but offers superior asymptotic performance for most operations. This PEP proposes replacing the makes two mutually exclusive proposals for including the BList type in Python:

  1. Add it to the collections module, or
  2. Replace the existing list type

It is currently rejected, but could be added to the collections module if there is sufficient outside interest. This is not quite the immutable vector from Clojure, but close enough: one merely needs to subclass it, and modify the setters (__setitem__, __setslice__, etc.) to first copy the collection and then operate on the copy. Copy-on-write ensures that only the changed leaf is actually copied, plus the internal nodes on the path leading to the leaf.

I’ve packaged this for Fedora (review request). Anyone cares to review it?

Technorati Tags: , , ,

ContactBot: noiselessly telling people where you are

Ever been in a situation where you are abroad for a short period of time, or you forgot your mobile phone charger, or otherwise not reachable at your normal phone number? I’ve been there, and it can be annoying to handle, unless you’re the kind of person who keeps lists (and even then, text messages ain’t free!). Or worse, you have several mobile phones, and you juggle them around, and people don’t know which one you are on right now…

There’s Google Voice, and other forwarding services, but that would require giving people a different number; one whose voice quality is probably not as good. And if the new number is only needed temporarily, that seems like an overkill.

Enter ContactBot. It provides a Twitter bot; you can tell it your phone number and location, and your friends (people you follow, not people who follow you) can then query the bot for your whereabouts.

The test bot is @hircus_contact. It is rate-limited at the basic 150 messages per hour, so if you want to heavily test it, or do not want to give me your phone number (I run the bot, after all!), feel free to check out the code and run your own bot!

Note that the bot does not currently add you back, so you’d have to wait until I personally add you before you can send direct messages. Should take less than a day.

TODO: timezone support, so the bot can warn your tactless friends not to call you at 3 a.m., documentation, and test cases. And online help.

Current command set:

  • D hircus_contact set phone 555-5555
  • D hircus_contact set location New York, NY
  • D hircus_contact phone ma_cherie
  • D hircus_contact location ma_cherie

Technorati Tags: , , , ,