Zovirl Industries

Mark Ivey’s weblog

Delicious Python

Organizing bookmarks is too hard. Does Backcountry Maps go under Maps or Backpacking? Does Hot Library Smut go under Libraries or Pornography? And how am I supposed to keep my bookmarks synched across 5 computers? I’m a busy guy, I don’t have time to figure this stuff out.

That’s why I’ve wanted to use del.icio.us for a long time. I was really excited when they announced their import tool. A few minutes later I was staring at 1000 poorly tagged bookmarks. Oops, should’ve cleaned them up before importing. After failing to find any way to batch process the mess, I dejectedly went back to my hierarchy.

I checked again today and there’s still no “Delete All” (the FAQ helpfully suggests canceling & remaking my account). Time to do it myself. I looked at the API docs (oh, I see, I’m not supposed to flood the server…) and grabbed pydelicious. Fired up ipython and had my bookmarks deleted in no time. Sharing all of my bookmarks turned out to be simple too: Since pydelicious doesn’t seem to understand private bookmarks [1] it shares everything. Changing my mind and deciding that I really should have tagged all my new bookmarks “import” (oops, again) was similarly easy. Hooray!

[1] It is unfortunate that the del.icio.us team doesn’t provide up-to-date libraries in a few languages. In a lot of ways I think that officially maintained libraries are an ideal answer to the SOAP vs. REST arguments

Animated housing maps

http://www.housingmaps.com/ is basically Google maps + Craigslist. Cool use of Google maps. Since it lets you pick a price range, it is super easy to make animated maps, showing the distribution of both affordable and luxury housing. Here’s one of downtown San Jose:

and one further up the peninsula:

steal the mouse back from SDL

I hate it when a poorly-behaved SDL app (usually mine) grabs the mouse, crashes, and doesn’t give the mouse back. Great, now I’m stuck in X with no mouse. Here’s a handy python script to get it back:

#!/usr/bin/env python
# get the mouse back after an SDL app crashes
import pygame
pygame.init()
pygame.mouse.set_visible(False)
pygame.event.set_grab(True)
pygame.quit()

Backpacking at Noble Lake

Last weekend my brother, Yana, and myself went backpacking at Noble Lake. This was the 2nd time we’d gone up to the Ebbett’s pass area (last time we went to Spicer Reservoir). I really like the area, especially Lake Alpine. Lake Alpine is simply gorgeous, and probably worth the drive all in itself.

We hiked in Saturday and found a campsite on a hill above the main lake. It was windy during the evening, and rained a little bit so we moved camp to a lower, more sheltered spot. Sunday morning we decided we would try to climb Highland Peak before going home. We didn’t expect to make it before our self-imposed noon deadline but ended up making really good time. We followed the trail towards Bull Lake, but at the saddle turned left and climbed the ridge towards the peak, which unfortunately meant we had to climb up and over Peak 9741. Next time, I would cut straight to the saddle between Highland Peak and 9741.

From the 2nd saddle, there was a faint trail up the ridge to Peak 10824. Mostly class 2, with a little class 3 near the top. We ended up not going past Peak 10824. Highland Peak was probably another mile away, but only 100 feet higher, and it didn’t seem worth it. We ate lunch on top and then headed back down. There was enough loose rock near the top to run down in great sliding leaps. We made it back down to the lake by around 3 and headed home.


More Photos

You can’t steal WiFi

Every time the legality/morality of using open wireless comes up, we are treated to yet another uninformed debate. People get worked up that someone might be “stealing” WiFi by accessing it without authorization but the analogies they use to explain why this is wrong reveal a stunning ignorance about how WiFi works. [1]

These are all actual analogies I have seen used to argue that using WiFi without express permission is akin to stealing:

Those analogies suck. WiFi is nothing like a door, or a garden, or a hose, or a bicycle. As a public service, let’s look at the basics of open WiFi:

  1. The router actively advertises the open connection
  2. The user’s computer asks to use the connection, and the router authorizes the request.

The conversation goes something like this:

Router: Hey, free Internet over here! Come and get it!
Computer: Hey, can I have a connection?
Router: Sure, here you go.

You want a good analogy for using open WiFI? Open WiFi is like using a web site. Do I have to call up Google and ask permission [2] before I do a search? No, because behind the scenes my computer is asking for me:

Computer: Hey google.com, can I have a list of pages about “tour de france?”
Google’s web server: Sure, here it is

My computer asks Google for a service, their server grants the request. That’s no different from using open WiFi: my computer asks your wireless router for a connection, and your router grants it. [3]

You still want to use a hose analogy? At least keep it accurate:
I stand on the corner with a hose yelling “Hey, free water! Come and get it!” A man walks up and asks “Can I have a drink?” I give him one. Did he steal the water?

You can’t steal WiFi.


[1] I only hope the people who finally decide on the legality of using open WiFi understand the technology. The recent “series of tubes” debacle doesn’t raise my confidence.

[2] At least I know who runs google.com. My computer sees 6 routers from my living room. If I wished to seek permission, which neighbors would I ask?

[3] Some argue that Google intends for their servers to be public, while ignorant owners of open WiFi do not. This is likely true, but the situation is really no different from if you posted a photo online without realizing it was publicly available. Would it be wrong for me to view the photo? No.

XCode & Python Resources

Some resources for using XCode with Python. A few introductory sites plus the ones I find most useful on a day-to-day basis:

XCode & Python Hints

Here are a few hints about how I set up XCode for Python development.

Run your program from XCode

Some versions of PyObjC have a bug so when you make new projects, XCode doesn’t know how to run them. Make a new custom executable & point it build/Development/myProgram.app.

No, don’t quit!

Having the keyboard shortcut to quit XCode be the same shortcut as quitting your application (cmd-Q) is a recipe for annoyance when you accidently hit it twice. Instead, go into XCode’s preferences and change the key binding to quit XCode to something like cmd-option-Q.

Faster builds

You can shave a second or two off the build-test-fix cycle if you set up a dummy “No Build” target. The Development build target will run every time but behind the scenes it isn’t copying files, it is just making aliases (py2app’s –alias option). Set up a new shell script target which runs /usr/bin/true and you can save the effort.

You have no debugger, but at least use PDB

If you set the USE_PDB environment variable, PyObjC will dump you at a PDB prompt when there is an unhandled exception. You can set this on the “Arguments” tab of the custom executable.

XCode & Python

Introduction

XCode is the IDE that Apple ships with OS X. Although primarily targeted towards C++, Objective C, and Java it also plays well with Python. It is excellent for writing OS X applications in Python thanks to good integration with Apple’s Interface Builder and py2app (the OS X distutils packager).

If you want to write OSX applications using python, XCode is the tool you want. This is thanks to solid integration with Apple’s Cocoa application framework and Interface Builder.

Debugger

First, the bad news: no debugger. XCode has a debugger but it doesn’t work with Python. You’ll have to use another tool like PDB instead.

Environment

Except for the debugger, the rest of the environment is nice. The UI feels like a proper OSX app, with all the standard keyboard shortcuts and controls, so you’ll feel right at home.

The UI is very flexible, and can accommodate a single fullscreen window or multiple separate windows for each file.

Editor

Standard features here. Syntax highlighting, split panes, menus to jump straight to a class or function. Content assist exists, but leaves something to be desired. I have yet to see a content assist for python that is able to keep up with the dynamic nature of Python classes, however.

Source Control

XCode knows about Subversion, Perforce, and CVS. File comparisons are done using Apple’s File Merge tool so you get nice side-by-side views.

Finding Stuff

“Find in Project” lets you search your entire project. Bookmarks let you quickly jump to common sections of code

Making OSX Apps

XCode is a great environment for Cocoa development. PyObjC provides the Cocoa bindings for Python, and once it is installed XCode knows how to make a new Python project. The distutils setup.py script is handled for you and you can create your .app bundle by clicking Build

Drag-and-Drop your interface…

Interface Builder lets you set up your widgets. Helpful guides pop up to help you position your widgets according to the Aqua guidelines.

…and then Drag-and-Connect your buttons

Hooking up buttons to actions in your Python objects is just a matter of ctrl-dragging from the button to the object.

Conclusion

If you want a Python IDE for your Mac, XCode is a good choice. If you also want to develop OSX applications in Python, XCode is a very good choice.

Magnetic Sense

A month ago Wired ran a story about people implanting tiny magnets in their fingertips so they can feel magnetic fields. Suddenly they can sense AC current in electrical cords, electric motors, the fields given off by transformers, and anti-theft gates in stores. Very intriguing, but stories of infected fingers and broken magnet pieces embedded under the skin didn’t sound fun.

Today as I was cleaning junk off my desk I found a tiny magnet. This suggested an experiment: would simply gluing the magnet to my finger be enough for me to feel magnetic fields? Super glue seemed the obvious choice but after two dried-out tubes I had to settle for wood glue.

Surprisingly, it actually worked. I could feel the motors running inside my electric razor. I could sense the AC current in the cord for our toaster oven, and could feel when the oven’s thermostat clicked on & off. The strongest field I found was from the AC adapter for our handheld vacuum. I could feel it from several inches away. Very, very cool.

Update: Lots of question from diggers, so let’s get some answers up:

Why? Because the idea of feeling magnetic fields intrigued me. What? You’ve never wanted to sense invisible magnetic fields? Never been jealous of geese with their internal compasses? Probably one of those things where if you have to ask, you’ll never understand.

Did I rip off my skin? No. It was only wood glue for goodness sake. I could barely get to to stay on my finger. I was originally going to try super glue but I couldn’t find any (all my tubes of super glue were dried out…why does that always happen?). Super glue isn’t that bad, though. The worst outcome is that you have a stupid magnet stuck to your finger for a few days. (I’m not responsible if you use too much glue and hurt yourself, don’t be stupid).

What about damaging your TV/floppy disks/credit cards/hamster? Well, just don’t go near your TV or credit cards while you have it glued on your finger. And who uses floppy disks anymore? Just use a little common sense: if you wouldn’t do it with a magnet, don’t do it with a magnet which is glued on your finger.

Why not use tape/band aid/something else? I tried tape, it didn’t seem to work. I think the glue did a better job of transmitting vibrations to my skin

What did it feel like? It felt like the magnet was buzzing, like a cell phone on vibrate but weaker. Another way to describe it is as a slight tingling.

Skiing at Carson Pass

We went skiing at Carson Pass on Saturday and found some nice corn below Elephant’s Back that worked well for practicing tele turns.

After the last time I went skiing, I posted some pictures to the telemarktips.com forums and asked for advice. Everyone said “shorter poles (so you can get lower)” and several people recommended reading Paul Parker’s Free Heel Skiing. I followed both bits of advice and it worked. I was able to link turns together this time, starting to get a feel for the flow between turns. It was awesome!

More photos