Skip to main content


Showing posts from December, 2012

Recover music files from iPod (Windows)

Problem: The computer with the original music is out of operation, leaving the only copy of music on the iPod. How to get the music back

On windows:
Connect the iPodDouble click on the iPod icon to open the folderIt will list four folders none of which contain music. The music folder is hiddenPress ALT+T to expose the tools menuClick on tools and show hidden filesEnter the iPod_Controller folderCopy all the subfolders under this into a temporary directory (say /OldMusic) on the new computer (the music files are here)Select all music directories under  /OldMusic and uncheck hidden (the folders are hidden)Open up iTunesClick ALT to bring up the menu barClick File->Add folder to add the folders to the library

Python: re (regexp): index of matches: difference between findall and finditer

using the findall method of a regexp will return all matches to the regular experession as a listusing finditer will return an iterator which you can use to interate through the matches if m is the result of then m.span() will give you the start and end indexes of the match and gives you the matchIf you have groups in the regexp e.g r"a(.*?)b" then will return the WHOLE matched expression and m.span() will return the corresponding start and stop indexes. To get just the particular group, for the expression given above, you have to do m.span(1) and

Python: using a regexp to do pattern matching on a byte stream

Python regular expressions are a very concise and efficient way of performing pattern matching on strings. Many computing problems involves a similar kind of pattern matching, but on arbitrary data. For my particular application I have a long sequence of one byte digital codes that indicate a sequence of runs for an experiment. Each run starts with the codes 9,9,9 followed by some codes telling me what happened during the experiment and ends with 18,18,18. I need to split up this long sequence of codes into runs and then parse the events in each run.

In the past I would have written a state machine to do this, but I thought, that's a waste: the regexp module already implements logic of this kind. So I came up with the following:

  ec = array.array('B', [ev & 0xff for ev in event_sequence]).tostring()
  separate = re.compile(r"\x09\x09\x09(.*?)\x12\x12\x12")
  trials = separate.findall(ec)

array.array converts the sequence of bytes into a fake string and the r…

apsw + cifs (samba) on ubuntu

Problem: a python program using apsw on MacOSX runs fine and fast using c.executemany to do inserts. When the same program is run on Ubuntu 12 the program runs very slow.

Solution:  Use transactions explicitly. Use a 'BEGIN' and 'END' statements to bracket the list of inserts. For some reason on Mac OS X this does not make a difference, but in Ubuntu it does

Problem: On Ubuntu a python program using apsw can create a database just fine on a local drive but on a samba (smb) network drive it gives the error: apsw.BusyError: BusyError: database is locked

Solution: use the nobrl option to mount. eg. in the /etc/fstab the line should look like

//server/path   /mnt/LabServer cifs nobrl,credentials=/my/home/credfile,iocharset=utf8,file,uid=1000,gid=1000