Thursday, May 13, 2010

Quick link: Knoppix on a USB jump-drive

Everyone's favorite bootable Linux CD can be written to a USB simply by running the flash-knoppix command:

  http://www.knopper.net/knoppix/knoppix62-en.html

It worked on an off-brand USB stick, but my SanDisk Cruzer refuses to play along. SanDisk implements their encryption via some weird juju that makes their USB drives very uncooperative; I wouldn't recommend them.

Thursday, May 6, 2010

Banksy?

Bren with a potential Banksy.

(And it seems that blogger strips EXIF tags from uploaded files.  No fun!)

Wednesday, May 5, 2010

Python debugging quickie

I've gotten into the habit of using pdb to interactively debug python code. I'll plug import pdb; pdb.set_trace() into the middle of an uncooperative function in order to examine machine state as the code runs.  (Note that I don't need to full capabilities of a debugger here; I'm not stepping through the code line-by-line.)

iPython is a much better choice, as this posting lays out:
import IPython.Shell; IPython.Shell.IPShellEmbed(argv=[])()

That's all you need to drop out of your function and into an iPython shell. When you're done twisting knobs, ctrl-D will exit iPython and return to your function.

Monday, May 3, 2010

Inchoate musing: what does it mean to own a device?

There's talk that the DoJ is looking into antitrust action against Apple for their recent decree that iPhone / iPad developers only use Apple-approved tools, ie, C/C++/Objective-C under Xcode.

I don't really know how antitrust law works, but it's not clear to me that Apple's move violates it. Microsoft was only prosecuted for bundling IE because they already had a monopoly on desktop OS's; it would be hard to argue that Apple has a smart-phone monopoly.

But I still think Apple's wrong, and government intervention is probably right.

In my mind, this falls under the broader problem of technology companies prescribing some narrow range of approved uses for the products we buy. A pernicious example is the license shipping with every camera that records video as MPEG or h264, which forbids making any money off any video you record with a consumer-grade camera, because that would make your work "professional." So if you've ever uploaded a video to YouTube, you probably violated your license.

I think I'd like to see something like a Gadget Owner's Bill of Rights: if I buy it, I can use it as I see fit. The vendor can eschew support for altered devices, of course, but I can't be legally prevented from modifying the device, and third parties can't be prevented from helping me.  (And let's pass laws to keep the 'Net neutral, while we're at it!)

Only moderately tangential updateReddit links to another great example of the kind of legal machinations that enable device manufacturers to claim excessive control over what you do w/ your device: a 92 page Terms of Service agreement.

Wednesday, March 17, 2010

More Python weirdness

You can almost use Python as a functional language, but ... you run into trouble.  The following code, discovered by Nithin Reddy, will raise an exception:

funs = [lambda i: i + j for j in [1,2,3,4,5]]
del j
funs[0](1)


The issue is that lambda, which executes in the context of the lambda call rather than the lambda creation. Using a proper def won't work either -- the following code fails in precisely the same way:
funs = []
for j in [1,2,3,4,5]:
  def f(a): return a + j
  funs.append(f)
del j
funs[0](1)



The fix is to curry your function:

def partial(f, *args, **kwargs):
  def bound_f(*args2, **kwargs2):
    x = kwargs.copy()
    x.update(kwargs2)
    return f(*(args + args2), **x)
  return bound_f

import operator
funs = [partial(operator.add,j) for j in [1,2,3,4,5]]
del j
funs[0](1)


I'm not quite sure what to make of this. Is function context bound on return?

Wednesday, March 10, 2010

Too many options

The autocomplete module that comes with jQuery UI is not the same as the jQuery Autocomplete plugin. Totally different interface.  Using the documentation for one while running the other will not make for an enjoyable afternoon.

jQueryUI comes with all manner of functionality beyond autocomplete, so that'd be my recommendation.

Friday, March 5, 2010

Write once, read many

Nice: the PEDANT database contains the output of many common genome annotation tools against 3,000 complete genomes, notably including the human genome. I've been looking for the results of running, say, TMHMM against every human gene.

(For more, see the paper: PEDANT covers all complete RefSeq genomes.)