It turns out /etc/profile and basrc are insufficient for GUI apps. You have to add stuff to some plist for system-wide paths.
Anyway I needed ndk-build in my path for Eclipse to auto-build my JNI/android code, so I created this file:
chef:jni vijayp$ cat ~/.MacOSX/environment.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PATH</key>
<string>/Volumes/LargeMac/android/android-ndk-r5b/</string>
</dict>
</plist>
How to get Lenovo x201 to connect 802.11n (n) wireless networks on Ubuntu. High speeds!
I recently upgraded my wireless router to 802.11n, as a first step in following in my friend Craig's footsteps. He has an excellent guide to setting up a new wifi router with ipv6.
I figured out what my wireless adapter was called by running
vijayp@ike:~$ lspci | grep -i net
00:19.0 Ethernet controller: Intel Corporation 82577LM Gigabit Network Connection (rev 06)
02:00.0 Network controller: Intel Corporation Centrino Advanced-N 6200 (rev 35)
My lenovo x201 has a Intel Corporation Centrino Advanced-N 6200 wireless controller, but despite upgrading everything, my laptop never seemed to be able to get speeds faster than 54Mb/s. It aggravated me that wireless was so slow! Running sudo ifconfig wlan0 showed only IEEE 802.11abg which seemed wrong. I first assumed it was a driver issue (despite these drivers having been integrated into the mainline a while back). I got the latest stable intel drivers (I used compat-wireless-2.6.38-3-ns.tar.bz2 but you should check the site to see if a newer one is there) , then the usual make && sudo make install, followed by a reboot. (I think you might need to have the kernel headers installed.)
Unfortunately, despite my shiny new drivers, the problem didn't go away. Finally, after much debugging, I realised that for some crazy reason, ubuntu ships with this default modprobe file:
vijayp@ike:~$ cat /etc/modprobe.d/intel-5300-iwlagn-disable11n.conf
options iwlagn 11n_disable=1
Delete this line, then reboot to fix the problem. But BEWARE. Apparently, there is a pretty serious bug in the drivers regarding problems with 802.11n support on intel hardware. One person reports that he has had no problems with the 6200, but another reports issues. Perhaps it's because I updated the drivers, but I have so far seen no problems with n working properly. There are a few notes in the recent latest changelog regarding changes to the lagn driver, including talk of new microcode, but I can't be sure that those changes have solved the issue. The launchpad bugs seems to be unclear.
---
Also, note that WMM (QoS) is technically required as part of a 802.11n deployment, and you must be running WPA2/AES to get 802.11n speeds.
vijayp@ike:~$ sudo iwconfig wlan0
wlan0 IEEE 802.11abgn ESSID:"TINAFEY"
Mode:Managed Frequency:5.785 GHz Access Point: 30:46:9A:00:E0:05
Bit Rate=108 Mb/s Tx-Power=15 dBm
Retry long limit:7 RTS thr:off Fragment thr:off
Encryption key:off
Power Management:on
Link Quality=53/70 Signal level=-57 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:13 Missed beacon:0
Setting primary monitor (with dual monitors) on Ubuntu 10.10 (maverick)
I have my laptop connected to an external monitor, and I want the external monitor to be the primary display (i.e. with the menu bar displayed on it.) For some reason, there's no GUI element to set this. I had to read a bunch of man pages, but when all else fails, trusty old xrandr to the rescue:
vijayp@ike:~$ xrandr --output HDMI1 --primary
In case you don't know what your display is called, just run "xrandr" on its own. This is what my laptop says:
vijayp@ike:~$ xrandr Screen 0: minimum 320 x 200, current 2880 x 1200, maximum 8192 x 8192 VGA1 disconnected (normal left inverted right x axis y axis) LVDS1 connected 1280x800+0+0 (normal left inverted right x axis y axis) 261mm x 163mm 1280x800 60.0*+ 1024x768 60.0 800x600 60.3 56.2 640x480 59.9 HDMI1 connected 1600x1200+1280+0 (normal left inverted right x axis y axis) 367mm x 275mm 1600x1200 60.0*+ 1280x1024 75.0 60.0 1152x864 75.0 1024x768 75.1 60.0 800x600 75.0 60.3 640x480 75.0 60.0 720x400 70.1 DP1 disconnected (normal left inverted right x axis y axis)
living life vicariously through my credit card
Because of fraud (see below) I have to get a new credit card number. I’m really bad at remembering to pay bills, so I have set up auto credit card charging of almost all of them. That makes this transition a major pain in the ass.
Ideally, I would be able to generate a unique credit card number for each payee, so that stolen info can be quickly isolated. Sadly the world doesn’t work like this (US cards don't even have chips in them!). My solution is to order two different cards on my account; I will use one exclusively for all my recurring payments (phone, cable, power, etc.) , and the other for all other transactions. That way, if I ever lose my card or need to get a new one, I won’t have to log on to 15 different places to change my card number.
Fraud:
It seems as though every time I'm travelling internationally, my credit card company gets worried about some "suspicious" international transactions and disables my card. This despite the fact that I purchased the tickets to this location on their card. They then try to call and alert me to this, but of course my phone is usually off to avoid usurious roaming charges. This leads to awkward “sorry sir, your card has been declined” moments.
Last week, however, for the first time I can think of, the automated credit card fraud detection system actually (kind of) worked. Someone, using a physical card my card’s info on it, went on a mini shopping spree in the Chicago area, starting with a $0.25 charge at a parking garage and culminating in a few ~$800 purchases at a grocery store(!). Since I still had my card in my physical possession, it seems likely that either a skimmer or some online leak of my card info occurred. It’s really kind of sad, cause I’ve always wanted to go to Chicago, and it seems as though my credit card has beaten me there! Living life vicariously through my credit cards, fun as it may seem, is a bit depressing.
lowering mouse speed (and sensitivity) in ubuntu 10.04
I bought a Evoluent VerticalMouse 3 a while back, and regardless of what settings I used, the mouse's movement was just too fast on Ubuntu. I set the mouse sensitivity slider in gnome to the least sensitive, but even that wasn't enough. After a bunch of playing around, I discovered that running this does the trick:
$ xinput --set-prop 'Kingsis Peripherals Evoluent VerticalMouse 3 ' 'Device Accel Constant Deceleration' 6
You can get a list of all properties with
xinput --list-props 'Kingsis Peripherals Evoluent VerticalMouse 3 '
Note that the Vertical Mouse 3 has a space at the end of its device string. This took me about 5 minutes to figure out.
Python quiz
What will this code snippet print?
#!/usr/bin/python
class A(object):
def __init__(self, a={}):
if not a.has_key('1'):
a['1'] = 1
else:
a['1'] += 1
print a['1']
for i in range(3):
_ = A()
(Hint: it's not not what you think.)
free Lonely Planet iPhone guides, today only.
Sorry if the title of my post sounds like it belongs on a splog, but I'm pretty excited about this. Apparently, the Lonely Planet folks wanted to help out those who are stranded in Europe, so they're giving away their iPhone guides free, until today.
You can buy them on your phone. Here are the cities that are covered:
- Amsterdam
- Barcelona
- Berlin
- Budapest
- Copenhagen
- Istanbul
- London
- Moscow
- Munich
- Paris
- Rome
- Stockholm
- Vienna
Here's how it looks in my iTunes store:

py2app, MacPorts, Snow Leopard, and PIL: a match made in Hell
For a while, I've been needing to create a little app out of some python scripts I'd been hacking on so I could have others use them easily. For those of you not familiar with it, py2app generates the equivalent of a statically-linked binary using python files and the transitive closure of all the libraries they require. This feature is pretty much standard for most compiled languages, and its presence makes python a pretty compelling development platform. (Actually, making a statically-linked binary on Mac OS is also really difficult, for reasons that are a bit outside the scope of this blog post).
It seems as though this shouldn't be difficult; like most development efforts on the Mac, one is easily lulled into a false sense of security ("It looks just like Linux; I bet everything works the same way!"). This is one of those times when you're rudely jolted back to the sad, disastrous reality.
I'd recently installed Snow Leopard on both my Macs, so I was already familiar with things randomly failing for no obvious reason, but I was not prepared for challenges of this magnitude! For those of you in a hurry, I'm going to just explain what you have to do to get this stuff to work properly. The curious (or should I say brazen?) can hear some more details later on in the post.
How to get py2app to work with PIL, numpy, etc on Snow Leopard
Here are some things that I've spent a lot of time figuring out:
- 64-bit python with Snow Leopard breaks pretty much everything.
- You can't use system Python (see below for what this is) because py2app refuses to build a standalone version with it, and because of the whole 64-bit problem. If you try, you'll probably get errors like this:
File "build/bdist.macosx-10.6-intel/egg/macholib/ptypes.py", line
48, in from_str
return cls.from_tuple(struct.unpack(endian + cls._format_, s), **kw)
error: unpack requires a string argument of length 8
> /Users/vijayp/src/build/py2app/examples/simple/build/bdist.macosx-10.6-intel/egg/macholib/ptypes.py(48)from_str()
-> return cls.from_tuple(struct.unpack(endian + cls._format_, s), **kw)
or this
4/6/10 5:07:10 PM com.apple.launchd.peruser.501[186] ([0x0-0x1d51d5].org.pythonmac.unspecified.hello[54121]) Exited with exit code: 255
or a bunch of other things. - Forget about mac ports. Without a huge number of patches, altered configuration files, and changes you have to make yourself to source files, it will never work.
The solution is to use one of the pre-compiled binaries built without 64-bit support. Here's how:
- To be safe, eliminate all traces of your various python installations to ensure that things don't get confused. Here are the Mac Ports Uninstall instructions.
- You might also want to blow away everything under
/Library/Frameworks/Python.framework/if you're paranoid. -
If you want to use object libraries like PIL, you're going to have to use python 2.5, so if you're hoping for something newer, you're kind of out of luck. Get
the Universal python 2.5 install image from the official python site. Install it. -
Close and re-open your terminal (to refresh your profile and bashrc), then ensure that your python is set up correctly:
terrance:~ vijayp$ python
Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
terrance:~ vijayp$ which python
/Library/Frameworks/Python.framework/Versions/Current/bin/python
terrance:~ vijayp$ file -L `which python`
/Library/Frameworks/Python.framework/Versions/Current/bin/python: Mach-O universal binary with 2 architectures
/Library/Frameworks/Python.framework/Versions/Current/bin/python (for architecture i386): Mach-O executable i386
/Library/Frameworks/Python.framework/Versions/Current/bin/python (for architecture ppc): Mach-O executable ppc
terrance:~ vijayp$ openssl sha1 `which python`
SHA1(/Library/Frameworks/Python.framework/Versions/Current/bin/python)= 675b28e55955734aba9e4df5d1ddd7d48ff9c83b
- Pull some stuff from svn
export BASE_DIR=/tmp
mkdir $BASE_DIR/build
cd $BASE_DIR/build
svn co http://svn.pythonmac.org/py2app/py2app/trunk py2app
svn co http://svn.python.org/projects/sandbox/trunk/setuptools setuptools
- Build it
cd $BASE_DIR/build/setuptools
python ./setup.py build
sudo python ./setup.py install
cd ../py2app/trunk
python ./setup.py build
sudo python ./setup.py install
- Now, you should have everything you need to build a little simple app without much trouble. First, verify that python and setuptools and py2app are installed correctly:
terrance:simple vijayp$ python
Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import setuptools
>>>
- Next up, try to get the example to work:
cd examples/simple
rm -rf build dist *.app
python ./setup.py py2app
open dist/hello.app
If you didn't get any errors, but an app just flashed in and out, you're in business. If you really care, you can open up the console log (in the Console app). You should have a bunch of environment variables printed. - Building the 3rd party libraries from source shouldn't be that difficult, but luckily, py25 libraries have mostly been built. Try installing PIL, then building the PIL example. It should work correctly.
Hopefully this little tutorial was helpful. Please let me know if it worked, or if it didn't.
Mac OS comes with a built-in "System Python," located in /usr/local/bin. As you can see, it's compiled for three platforms, 64-bit, 32-bit, and ppc:
terrance:~ vijayp$ file /usr/bin/python
/usr/bin/python: Mach-O universal binary with 3 architectures
/usr/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64
/usr/bin/python (for architecture i386): Mach-O executable i386
/usr/bin/python (for architecture ppc7400): Mach-O executable ppc
py2app requires a couple of generic system libraries contained in the setuptools package, especially macholib, this library that can interact with OsX object files. There are many instructions online about how to install these; I tried a number of different things, and a combination of easy_install, compiling source, and port install packages sort of worked. Unfortunately, I was never able to compile or install a PIL that would embed its .so into the python archive. I didn't spend too much time on it, though, since I really needed a standalone python archive. Apparently, a Mr. Brant Faircloth (cool name!) figured this out at some point, but I wasn't able to get it to work
Next up, I tried to use Mac Ports to install python. I tried following Aral Balkan's instructions, and a number of other random ones. I tried compiling from source, using python-25 ports, python-26 ports, and even python-24 ports, and all failed with one of the two errors I quoted above. I tried installing universal versions of them using sudo port install python-25 +universal, and also by setting the architecture to i386 in the macports configuration file.
The most common error I saw was this:
File "build/bdist.macosx-10.6-intel/egg/macholib/ptypes.py", line
48, in from_str
return cls.from_tuple(struct.unpack(endian + cls._format_, s), **kw)
error: unpack requires a string argument of length 8
> /Users/vijayp/src/build/py2app/examples/simple/build/bdist.macosx-10.6-intel/egg/macholib/ptypes.py(48)from_str()
-> return cls.from_tuple(struct.unpack(endian + cls._format_, s), **kw)
I spent a couple of hours perusing the source -- it helped me get a clearer picture of the issue. It appears to be the result of parts of the macholib code having trouble pulling information from object files that have both 64- and 32-bit versions in them. I'm not sure why; perhaps it's because both architectures are viable?
Sadly, figuring this out fully would take me a week, and my time is limited. I'm sure an expert could figure this out soon. I worked with a bunch of incredible python gurus at Google, and some of you guys read my blog! Hint hint!
(While we're on this subject, the lack of strace has been bothering me for some time. It turns out dtruss is a reasonable replacement.)
Vancouver Olympics (part 1 of … many)
I spent 10 days in Vancouver during the Winter Olympics; my time there was certainly one of the most enjoyable experiences I can remember. I had intended to keep updating my blog regularly, but alas, the best I was able to do is to keep a few notes and resolve to post retroactive updates later.
Well, later starts now!
Luckily, I was able to sublet a great little one-bedroom (owned by a friend of a friend) in the centre of Yaletown. Normally yuppie-central --- think tiny little dogs with clothes on them and women too skinny to hold their hands with gigantic engagement rings up --- the area was a short away from a lot of the outdoor evening activities, the venue for the closing ceremony, and the hockey arena. The place was on the 23rd floor of one of the many residential high-rises in Vancouver, and as such had a pretty great view! It even had laundry in-suite, which was quite convenient given my long stay. Here's a photo looking out (and in) from the place. Fred has some photos from the balcony, and I'll post them when he sends them my way (soon!).


In lieu of a rubbish chute, they had a series of trash compactors in the basement which fed directly into huge dumpsters. Residents are expected to carry their trash to the basement and dispose of it that way. I wish I'd taken a photo of it; it's probably the only time I'll ever get to operate an industrial-strength trash compactor!
In preparation for the Olympics, the city built a new subway (SkyTrain, as they call it) line from the airport, through the heavily ethnic Richmond suburb, past the curling venue (more on this later), through Yaletown and right to downtown. Apparently, this line was completed way ahead of schedule, and under budget. I was really impressed with the train --- although after living in New York for so long, it is a bit disconcerting to be in such a new, clean station. The coolest part (for me anyway) is that the train is totally automated and computer controlled. If one sits at the front of the first car, one could almost pretend that one is driving it. Not that I did that. Of course...

While I'm on the subject of trains, the city also built a single-tracked light rail line ("The Olympic Line"), apparently for the purpose of shuttling people between Granville Island, a renaissance-fair kind of tourist trap, and their accommodations. The train was borrowed from a Belgian city, much to the amusement of my Belgian friend Frederick, who was with me at the time. All in all, this train line seemed to be pretty useless. I hope there are plans for expansion!
The Nightlife/Partying:
Although Vancouver was, with a metro population of about 2.5 Million, the largest city ever to hold the Winter Olympics, the impact of the tourists was still marked. I can only imagine how Lillehammer, a city of 20k, dealt with such a huge influx of people. There were three many night-time areas where people congregated: Granville St, Robson Square, and Yaletown.
1. Granville St.
The authorities shut down the main downtown street of Granville to all automotive traffic and made it a large pedestrian mall. Most of the times at night, however the street was so crowded with revellers that it was impossible to move. For the most part everyone was very well-behaved! I've included a few videos from various days.

2. Robson Square
Robson Square is a large public square with an art gallery and a skating rink. This area was closed off daily and had large throngs of people at all hours. Each night, VanOc put on a light/firework show synchronized with music and people riding down a long zipline they set up. On some nights, there were upwards of 100000 people in the area watching the show. I saw a few people who brought large boomboxes playing dance music. They quickly got a huge following of people dancing in the streets. This was a common theme, and I saw it in many other places.
(I can't seem to find a photo of Robson Square now. I'm sure I have one somewhere.)
3. Yaletown
Yaletown park was the site of daily special concerts set up, and its own fireworks/light show. Unfortunately I wasn't able to make it into any of the more popular bands' shows; some people lined up 5 hours before some concerts to guarantee space. Here too, the streets were shut to traffic and filled with many people when the weather was nice. Many restaurants and bars on the street were open extra-long hours.
At this point, I've provided a decent overall summary of the Olympics in Vancouver. At this point, I'm going to do a day-by-day summary of my experiences, building on my notes! I'm going to split it up into a bunch of different posts though, since I don't have the attention span to write it all at once (and you probably don't have the attention span to read it all at once either!)
The Games!
Well, I guess it's about time we talk about the games. More on them in my next post!
En route to the olympics!
I wrote this post last week, more on my Vancouver experiences soon!
--
I'm currently on the plane to Seattle, the first stop on my February/March adventure! After spending about a day in Seattle with friends, I will be heading up to Vancouver to partake in Olympic madness for about ten days.
A friend of a friend was nice enough to sublet me his furnished condo really close to the venue, and many of my friends will be staying in various places around vancouver, going to a bunch of different events. So far, I have tickets to ski cross, a few quarter-final hockey games, curling, and the closing ceremonies. I'm going to try my best to get tickets for the semi-final hockey match but currently they're going for a few thousand dollars a piece on craigslist, so I'm not holding my breath. I think it will be a lot of fun to watch the Gold Medal game in the public broadcast centre; if Canada makes it, I'd be surprised if most of the city isn't out somewhere watching the game! A victory would lead to partying the likes of which man has rarely seen! I'll most certainly post more info and pictures when I get to Vancouver!
The preponderance of WiFi on airplanes, though incredibly useful in abstract, is probably a net negative for me. I used to look at pan-continental flight as one of the few places devoid of the time-wasting temptations of the Internet. If I'm lucky enough to be sitting in a seat with power, I often think of the 5+ distraction-free hours as some of my most productive! I've written a few papers, an entire web application, planned out large changes in my life, and read some pretty interesting books on these long flights.
Luckily, this time, I was able to resist the temptation of WiFi, and instead fixed a bunch of bugs in some code I was writing, start work on an additional module for an application I've been writing for Acumen Fund (more on this later!), write this blog entry, and listen to a few more lectures from this Intro to Philiosphy class I found on iTunes edu.
Looks like we'll be landing in Seattle soon (only 2 hours late, way to go Delta!) so I guess that's it for my blog entry! Stay tuned for more!