June 8, 2010

Mutliple non-admin users of GoogleAppEngineLauncher under OS X

If you do the right thing® and work as a non-admin user under OS X (10.6 / Snow Leopard), you will get strange errors if you are multiple users who try to use the GoogleAppEngineLauncher in order to toy with Googles awesome AppEngine: Only the non-admin user who (last) installed the program is apple to start the local server, everybody else gets an error that the server is unable to launch google/appengine/tools/os_compat.py or some such.
Turns out it's a permission problem: some of the files (which in my case are owned by sara:admin), doesn't have read/execute permission for everybody else:
fladmast:Contents janus$ pwd
/Applications/GoogleAppEngineLauncher.app/Contents
fladmast:Contents janus$ find . -name '*.py' -not -perm -005 | wc -l
     466
fladmast:Contents janus$ ls -l `find . -name '*.py' -not -perm +005 | tail -n 1`
-r-xr-x---  1 sara  admin  1938 May 16 08:28 ./Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/tools/bulkload_client.py

The fix is simple: Open a terminal and fix the permissions:
fladmast:/ janus$ cd /Applications/GoogleAppEngineLauncher.app/Contents/
fladmast:Contents janus$ sudo chmod -R +r,+X .
(That's a capital X in the chmod)

March 24, 2010

Scan processing with pdfimages and ImageMagick

Just for my own reference, the following procedure works quite well for turning greyish pdf scans into something printable:
pdfimages foo.pdf img
for a in *.ppm; do convert $a -level 50%,80%  ${a%ppm}png ; done
This uses pdfimages (on OSX you can grab the xpdf package from MacPorts) for extracting images from the pdf file, and then ImageMagick convert (probably MacPorts again) to set the white and black levels to 50 and 80 percent respectively. Without pdfimages, ImageMagick just calls ghostscript to convert the pdf at a fixed resolution which is of course useless for this purpose. Next time I might have a look at the contrast-stretch and auto-level options which might be a bit more robust.

January 1, 2010

Checking GMail contacts for iPhone sync issues

Google sync allows you to push sync your Google contacts to your iPhone. There are some quite arbitrary restrictions on the type and quantity of phone numbers that can be synced, as described here. Running the following piece of python next to an exported google.csv will check for entries that will loose phone numbers:
#Check a google.csv contact dump for iphone sync issues.
import csv
import collections 

#This is the problem: iPhone (when synced via exchange?) only allows
#a limited number of phone numbers -- which must be of specific types.
# See www.google.com/support/mobile/bin/answer.py?answer=139635&topic=14252
PhoneLimits={
 'Home':2,
 'Home Fax':1, 
 "Mobile":1, 
 "Pager":1, 
 "Work":3, 
 "Work Fax":1
 }

def limitViolations(limits,types):
 for (type,num) in types.iteritems():
  if num>limits.get(type,0):
   return '%d > %d entries of type %s'%(num,limits.get(type,0),type)
 return ''

reader = csv.DictReader(open('google.csv','rb'),quoting=csv.QUOTE_MINIMAL)
nPhone=-1
for row in reader:
 # First pass only: see how many phone columns are active
 if nPhone<0:
  nPhone=1
  while row.has_key('Phone %d - Type'%nPhone):
   nPhone+=1
  nPhone-=1
 # Use phonetypes to tally the types for the active row
 phonetypes=collections.defaultdict(int)
 for kPhone in range(1,nPhone):
  #if a phone value is given for this index, tally the type
  if len(row['Phone %d - Value'%kPhone])>0:
   phonetypes[row['Phone %d - Type'%kPhone]]+=1
 v=limitViolations(PhoneLimits,dict(phonetypes))
 if v:
  print('%25s: %s'%(row['Name'],v))



December 7, 2009

Restricting sshd to private key authentication on OS X 10.6

Mostly just a note for next time I have to do this.

Actions:

1) Edit /etc/sshd_config

cd /etc/
sudo cp sshd_config sshd_config.orig
sudo cat 'ChallengeResponseAuthentication no' >>sshd_config

2) Enable ssh

Go to sharing preferences and enable ssh for the relevant users.

Background

That should do it, other options are already ok by default:
# To disable tunneled clear text passwords, change to no here! Also,
# remember to set the UsePAM setting to 'no'.
#PasswordAuthentication no
#PermitEmptyPasswords no
Note that the comment is completely incosistent: the default is already 'no', and there is no need to set UsePAM no, as described further down in the config file.

November 18, 2009

Installing scientific Python on OS X

Just had a very nice experience getting a full scientific Python up an running on OS X in five minutes thanks to the Enthought Python Distribution. The hardest part was deciding not to build things myself: Although Enthough Python is free for academic use, it is not free in Stallman terms. Still, the knowledge that it is made from free components and that you could in principle build everything yourself makes for a nice untrapped feeling. Python is quickly becoming the language of choice for numerical physics, either on its own as a front-end to high performance C/Fortran code. In spite of the 'batteries included' Python policy, you need a few addons to really get scientific Python code going: Although OS X comes with Python installed, you will likely want to install a separate version for coding: both to keep up with the Python community, but also to avoid polluting the official OS X python with you additions. The two obvious ways to add an extra Python are
  • Install via MacPorts, one of the opensource software managers for OS X
  • Install MacPython which is the OS X version of the standard Python distribution
After browsing quite a bit, it seems that getting the "big 3" up an running with either Python is a mess, at which point I ended up decided to go for Enthougth. An unrelated figure (made in Mathematica)

May 15, 2009

Time for a picture

Ten minutes with Mathematica to illustrate why trying to rotate spins with transverse fields is futile...

Moving Picasa database from Window to Mac OS X

In the process of consolidating the digital presence of the family on a beefed-up MacBook, I have come to the point of moving the digital photo library. Moving the files almost did the trick, but to get my Picasa albums across, some hacking was required: We currently handle the library with Google Picasa which (apart from being very nice to work with) does things "the right way": It does not touch your original photo files, allowing you organize your them according to your desires, and it stores the metadata in the most accessible form possible:
  • Image edits does not affect original files: instead the edits are stored in picasa.ini files in the same folder as the file.
  • Keywords (tags) and captions are stored as IPTC comments directly in the photo files.
This means that if you just move your photos (with associated picasa.ini files) across from Windows to Mac, and fire up Picasa you are almost back to start with the only thing missing being information about albums (ordered collections of photos). The following is a recipe for getting that last piece across.

Outline:

  1. Move photo files to mac. Make sure to grab a copy of 


    1. <picasadir>/Picasa3Albums (as a zip file)
    2. <picasadir>/Contacts/contacts.xml


  2. Install and start Picasa, create an album and quit when scan has completed (skip face scan).
  3. Edit album (.pal) files to match new file location.
  4. Put .pal files as ~/Library/Application Support/Google/Picasa3/Picasa3Albums/<databaseid>/<albumid>.pal
  5. Replace <picasadir>/contacts/contacts.xml with old version
  6. Delete ~/Library/Application Support/Google/Picasa3/db3 to force database rebuild.
  7. Start Picasa and watch your albums and people appear :)

Detailed notes

The album information are stored in .pal files below your google folder:

google
+ Database ID
  + Album1 ID.pal
  + Album2 ID.pal
  + Album3 ID.pal
  + ....
where Database ID and Album ID are MD5 hash strings. The google folder is located as follows:
Vista
C:\Users\<username>\AppData\Local\Google
XP
C:\Documents and Settings\<username>\local application\Google
OS X
/Users/<username>/Application Support/Google/Picassa3/
You want to grab the whole folder Database ID and copy it to a zip on the mac (keep the original zipped because Picasa eats the pal files if it sees them when scanning). The .pal files are xml files. Search and replace over all of them to get the image paths right. I used two passes: first pass to convert \ to /, and second pass to correct the beginning of the paths.

Update

Just added step 5 to include the 'people' data as well. The image-specific data is stored in the picasa.ini file (again, Google is doing things the rights way), but this only links a given person to a unique number. To link that number to an actual person, you need to copy the file contacts.xml across as well.

March 13, 2009

Local DOI resolver?

With LaTeX, Bibtex and the hyperref package, it is quite easy to spit out bibliographies with links described by the Digital Object Identifier (DOI). Clicking these links takes you to the journals abstract page for the work in question, where you can usually directly download PDFs (due to the everpresent IP-zone based royalty schemes most university have set up). This is nice and all, but what should really happen is of course that you local pdf copy should be accessed: Accessible even without net, containing your personal notes, etc.

So how to catch the links? Although DOI is actually a URN (i.e. DOI: is a valid link) (well almost -- according to this page, it is actually not registered), this seems completely un-implemented (you can get a Firefox plugin if you like), so most places resort to making DOI links go to the HTTP resolver at http://dx.doi.org. This means that in addition to writing a DOI handler (that looks for local copies and otherwise passes of to doi.org), I need to set up something that catches requests to http://dx.doi.org and maps those to the DOI handler. Hmm