Importing a CVS repository to Google Code Subversion

My C BitTorrent implementation, Unworkable, used to be hosted on an anonymous CVS repository I had running on my server at home. This was fine, until I reinstalled the machine from scratch and didn’t feel like setting up the whole anonymous CVS access again. Its a pretty painful process, unfortunately, although there is this guide to setting up anonymous CVS.

No public VCS, bad for an Open Source project

So, for a while, there was no public source control for Unworkable, which sucked. Its difficult and cumbersome for other developers to write diffs and track changes without one. While I generally like to maintain full control of the source code hosting, I’ve had good experiences with Google Code before. They don’t show ads, and their interface is clean and to the point, unlike say SourceForge, which is covered in ads and various nonsense.

Anyway, I had a CVS repository and I first wanted to convert it to Subversion, including all the history, then I wanted to import that into Google Code.

Converting from CVS to Subversion

The first thing to do was to convert my existing CVS repository to Subversion. There is a nice tool specifically for this, cvs2svn. It is in fact very easy to use, at least in my basic case – I only work with HEAD or in SVN terminology, trunk. I simply ran:

cvs2svn --trunk-only --svnrepos ~/unworkable-svn ~/unworkable-cvs

Et voila, I have a shiny new Subversion repository in ~/unworkable-svn, with full history.

Importing Subversion repository to Google Code

Google Code lets you import an existing Subversion repository pretty easily, as long as you have an empty project. When your Google Code project is created, it will be set to revision 1. In Subversion-land, revision 0 is sort of magic, and so you will need to overwrite it to properly import your existing repository. Google give you a place to do this, but its slightly confusing because they don’t put it under ‘Administer’.

In order to reset your repository you must:

  • Log into your Google Code project with administrator privileges.
  • Browse to the ‘Source’ page (either ‘Checkout’ or ‘Browse’ but not ‘Changes’).
  • Scroll to the bottom of the page, and click the ‘reset this repository’ link, which is sort of hidden.
  • Choose the option “Did you just start this project and do you want to ’svnsync’ content from an existing repository into this project?”
  • Click the big “Reset Repository” button which has a big red warning label beside it.

Now you are ready to import your repository. You will use the ’svnsync’ tool included in Subversion 1.4 and up to do this. There are two commands, one which takes a path to both the Google Code repository and your repository, and another which takes just a path to the Google Code repository. The first one will run quite quickly, the second one can take a while as it imports each individual revision,

# This command takes both the path to your Google Code repository
# and the path to the repository you want to import
svnsync init --username YOURUSERNAME 
    https://YOURPROJECT.googlecode.com/svn file:///path/to/localrepos
# This command takes just the path to the Google Code repository.
# It will take a while to complete.
svnsync sync --username YOURUSERNAME https://YOURPROJECT.googlecode.com/svn

Once you’ve done that, your code is imported. Enjoy!

CrossFit and quitting coffee

Although I enjoyed both the taste and ritual aspect of coffee, around six weeks ago I decided I was too dependent and that it was having a negative effect on me. Specifically, I felt like it was sapping my energy and leaving me with a kind of brain fog around mid afternoon that nothing could fix. Drinking more coffee wouldn’t help at all. I had also noticed that the acidity of coffee was contributing to indigestion. I guess I was drinking two large cups of strong drip coffee per day on average, sometimes more, sometimes less. I would also drink green tea in addition to this. Aside from the morning dependency (MUST have coffee before starting work), the mid-afternoon mental slowdown I’d experience sometimes, and the increased stomach acidity, I didn’t have any greatly negative experiences – unlike other people who have trouble sleeping, get very anxious, and so on. I could drink many cups and not have any real problems. I never drank coffee immediately before a work out so I’m not sure if it was helping my performance much.

It seems that there is no clear cut story about the long term health effects of coffee or caffeine. There are plenty of studies on both sides of the issue – some report that caffeine contributes to high blood pressure, increases stress, leaches calcium from the body, and so on. Others point to increased athletic ability, protection against cancers and protection against Parkinson’s disease. I found this post on the CrossFit Santa Cruz blog which seems to reach a similar conclusion.

I didn’t find it hugely difficult to give up – I simply decreased initially to a single shot in the morning for a week, then I dropped it off completely substituting black or green tea, and then gave up completely. I suppose its been over a month now since I last had coffee. I don’t have any particular urge to drink it, I’m happy enough with herbal teas and the occasional black or green tea when I feel like it. I don’t notice a huge difference in how I feel apart from a reduction in what I call brain fog, and of course not craving coffee in the morning. I don’t think coffee could have been helping my CrossFit performance that much – since quitting coffee my Fran time has dropped by a minute and a half. On the other hand, I’m not implying any causality in that – I’m sure my performance would have improved if I hadn’t quit coffee.

Overall, I feel like being dependent on any substance for a long period of time is not good, that its healthy to break these mild addictions. Its rewarding just to know I can, and also not to have any pressing need to either brew a cup or pay someone else to brew one for me. I think I’ll stay off coffee for the foreseeable future – I feel more free without it.

OpenBSD 4.5 is out, solid release, but some package bugs

OpenBSD 4.5 was released the other day. I upgraded one of my servers and workstations to the new release, from 4.4-current and 4.4-release respectively. Mostly, things have gone pretty smoothly, as is usually the case with OpenBSD. The new release has plenty of incremental improvements, with the developers gradually polishing and refining things such that the operating system as a whole gets better and better.

Some of the highlights for me include the new multi-plexing, re-sampling, low-latency audio server aucat(1), the new even-stricter malloc(3) which can catch buffer overflows of even a single byte. Additionally, the Atheros wireless driver, ath(4), which I have in a couple of my laptops, now supports WPA.

All in all, lots of nice improvements which make OpenBSD even more of a pleasure to use. I did however come across one nasty bug after upgrading one of my servers. We use the symon system monitor on all our servers to log and graph all the sorts of system and network metrics you’d expect – cpu usage, disk, memory, network io, etc. This is very useful for capacity planning and also for spotting bugs or mis-configurations. Especially on a shared, multi-user system you want to keep an eye on resource utilisation over time. Unfortunately, the 4.5-release symon package for amd64 would exit after startup. When I ran it in debug mode, it gave me a ‘Bus error’ – then when I twiddled the symon.conf a bit more to remove some sensors, it would exit with a segfault, and finally I could get it to run by disabling some stuff but it would spew warning messages to standard IO. Specifically, it had a problem with the if(lo0) and if(bnx) sensors. If I disabled those, it would run, but spit out warnings. However, these sensors were pretty useful to me, so not having them was very annoying.

I noticed some recent commits to the -current symon port, so I decided to give that a shot. Its always pretty hairy building -current ports on -release, but in this case I didn’t have much choice. Fortunately for me, the -current symon port built and ran fine, completely eliminating the issues I’d had with the 4.5 -release packages. So, this was a mild annoyance, although it does highlight the sad demise of the -stable ports tree.

Overall, 4.5 is a solid release with plenty of new features, just be warned that the symon package might not work out of the box for you, if you rely on it.

Apache mod_rewrite RewriteRule with query string

I was converting some mod_rewrite rules from the Lighttpd webserver to Apache today.

While Lighttpd and Apache both have request rewriting modules with pretty equivalent functionality, there are some significant differences nonetheless. Specifically, I was trying to rewrite a URL of the form:

/script?key=123abcxyz

to a file on the local disk:

/abc/123/123abcxyz

In Lighttpd, I had a single rewrite rule handling both the URL and its query string:

"^/script?key=(([0-9a-f]{3})([0-9a-f]{3}).*)" => "/$2/$3/$1"

The regular expression might be a little confusing at first, but its reasonably straight forward.

My first thought was that I could do pretty much exactly the same thing with an Apache RewriteRule, like so:

RewriteRule ^/script?key=(([0-9a-f]{3})([0-9a-f]{3}).*) /$2/$3/$1

Unfortunately this won’t work – the RewriteRule will only be passed the URL – that is, /script without the query string (?key=foo).

So how do you make the RewriteRule aware of the value of the query string to rewrite to the local on-disk file correctly? You must have a RewriteCond directive preceeding the RewriteRule. RewriteCond can run a grouping regular expression over the query string, and RewriteRule can pull those groups out of the previous RewriteCond with a special syntax:

RewriteCond %{QUERY_STRING} key=(([0-9a-f]{3})([0-9a-f]{3}).*)
RewriteRule ^/script /%2/%3/%1

So there you are – how to have an Apache RewriteRule operate on parts of the query string as well as on the URL. The solution ends up being a little more convoluted under Apache than under Lighttpd, but is still manageable.

Small free as in beer CD/DVD emulator for Windows

I use Windows sometimes and its very useful to be able to mount CD/DVD image files rather than having to waste a disc burning them to physical media.

Of course, this functionality is included with most free operating systems like OpenBSD and various Linux distributions. However, on Windows, most of the well-known applications with this capability are commercial shareware (DaemonTools, Alcohol 120%).

While its not Open Source, I came across SlySoft Virtual CloneDrive. This is a small freeware application which can mount various formats of CD/DVD images. It doesn’t have any annoying nags and works just fine.

OpenSocial, Signed Fetch and 2-Legged OAuth

I’ve been doing a fair amount of work with OAuth and OpenSocial for Freebase recently. Its been interesting to learn about the differences between 2-legged OAuth (aka Signed Fetch) and 3-legged or “normal mode” OAuth.

Essentially, normal 3-legged OAuth facilitates permissions delegation between an application which wants to do something on your behalf and a web service provider without any existing trust relationship. It is a way for a third party application to use your account at some other site on your behalf. In the case of Freebase, it allows third party applications to write to the system using your account – without having to give them your username and password.

2-legged OAuth is actually a lot simpler. Actually I don’t really see why its called OAuth at all – its an unfortunately little-documented variation with completely different parameter names. That’s probably why it is better known as “signed request” or “phone home” among Open Social developers. Indeed, the Open Social documentation for the gadgets.io.makeRequest() function is pretty clear that signed authorisation is NOT OAuth, but merely uses the signing method outlined in section 9 of the OAuth specification.

2-legged OAuth implies a pre-arranged trust relationship between actors (typically OpenSocial hosts (or “containers” ) and API providers). The OpenSocial container proxies the user’s request, cryptographically signing it with HMAC-SHA1 or RSA-SHA1, depending on the specific container. The API provider who receives this request must already share a secret with the container (in the case of HMAC-SHA1) or have a copy of the container’s public X509 cert (in the case of RSA-SHA1) in order to verify the signature – hence the pre-existing trust relationship. Because of this pre-existing trust relationship, the “prompt user to allow permissions” step can be skipped.

2-legged OAuth uses a quite different set of parameters compared with normal 3-legged OAuth. For example, there is no xoauth_requestor_id parameter nor is there an oauth_token parameter. Instead, you will want to use the various Open Social parameters – opensocial_viewer_id, opensocial_app_id and opensocial_owner_id. Furthermore, the values of oauth_consumer_key is the name of the signing site.

The best documentation I have found on accepting these 2-legged OAuth or “signed fetch” requests is over at the OpenSocial Wiki, specifically the pages titled introduction to signed requests and validating signed requests. Also the Open Social documentation

It is a bit tricky to support both 3-legged OAuth and 2-legged OAuth modes.

Pylons tip #4 – SQLite3, datetime.date and datetime.datetime handling

I wrote in a previous article about using SQLite with Pylons. SQLite is great for small-to-medium web projects and also prototyping. Its not very hard to port a SQLite implementation to a more robust and scalable RDBMS such as PostgreSQL.

Anyway, if you have used SQLite in any capacity, you have no doubt noticed that it does not have very strict type enforcement. You can put pretty much whatever you want into a column. This isn’t a big deal when you are working with a dynamically-typed language such as Python. Its pretty trivial to convert an integer to a string or vice-versa. One exception to this is with datetime.date and datetime.datetime objects. Date objects map nicely to the SQLite ‘DATE’ type and datetime objects map nicely to the SQLite ‘TIMESTAMP’ type.

Its very common that you will want, in your Python code, to deal with real datetime or date objects, for the purposes of arithmetic or formatting. It can be a real pain in the ass to manually convert your datetime/date objects to and from SQLite-compatible string representations – both for results going out of the database and for values going into the database. Luckily, you don’t have to!

Python’s sqlite3 module has native converters for both these types. You simply need to ensure that your SQLite schema has the correct types specified for the columns, and sqlite3 can do it for you. For example, here is a basic table definition:

1
2
3
4
5
6
7
CREATE TABLE rateable_scale(
rateable_scale_id INTEGER PRIMARY KEY,
rateable_scale_creator TEXT,
rateable_scale_created_date TIMESTAMP,
rateable_id INTEGER,
scale_id INTEGER
);

In this example, I expect the column ‘rateable_scale_created_date’ to map to a datetime.datetime object in Python – which maps to a ‘TIMESTAMP’ type for SQLite. Once you have your column types specified correctly, you simply set up your SQLite connection in Python with a couple of extra options:

1
2
3
4
5
6
7
def connect_file(self, filename):
    ''' Connect to the provided DB file '''
    self.conn = sqlite3.connect(filename, detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)
    # this row factory makes the results objects accessible both by index
    # and by column name
    self.conn.row_factory = sqlite3.Row
    self.connected = True

The important part of the above snippet is the connect line:

1
self.conn = sqlite3.connect(filename, detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES)

Notice the detect_types parameter. This is what instructs the sqlite3 module to magically convert date and datetime objects for you!

In search of a decent music player for Windows – Songbird

On my home desktop, I dual boot Windows and OpenBSD. Under OpenBSD, I have a few good choices for music players. Since I’ve taken quite some effort to organise my music collection – which resides on a 2T RAID 5 array on my OpenBSD server, served up via NFS / Samba – Xmms, Amarok or even mplayer work fine for me. I tend to listen to music on a per-album basis – and all my music is in a hierarchy of genre/artist/album.

But what about Windows? I really hate the venerable WinAmp these days – I find it bloated, unstable and slow. I also dislike Windows media player for similar reasons. Up till now I’ve been using VLC for Windows, which is nice because it at least supports all the formats I need out of the box (MP3, Ogg, FLAC).

About a year ago I tried out this new-fangled thing with a lot of hype around it (at least here in SF) called Songbird. Back then, it was horribly poor quality, and just plain didn’t work. I distinctly remember the ‘exit’ button not functioning in the program, and having to manually kill it from the Windows process manager. However, today I decided to give it another try. While its still pretty bloated (12M download), it at least seems to work! Actually its fairly decent. Like Amarok, its essentially an iTunes rip-off. In other words, it allows you to browse your music collection easily whether or not you have it well sorted. Songbird scanned my 102G music collection over Samba in only a few minutes, and so far has been quite stable. So if you are looking for a fairly decent music player for Windows (and apparently it runs on some other platforms too) why not give it a try?

Strength training with gymnastics rings

Through CrossFit, I’ve recently heard about the benefits of training with gymnastics rings. Today my rings, which I purchased from RingTraining.com (affiliate link) for a pretty reasonable price, arrived – and I’ve been using them a bit. To get an idea of the kind of strength training you can do with rings, check out this example of the very difficult Iron Cross skill:

The three main exercises I’m interested in performing (or at least, trying to perform) are ring pull-ups, ring dips and the muscle-up. Pull-ups on rings can supposedly be a bit easier on the shoulders than static bar pull-ups, and since the rings move, can require some core strength to stabilise the body. Some people train pull-ups solely on rings because of the shoulder relief they can offer.

Doing dips on the rings is quite a bit harder than doing them on a standard, static gym dip-frame, again because the rings move and you must work a lot harder to maintain stability. I find my arms shaking after doing just a couple of ring dips – something I’ve only had happen after a few hundred reps on the static bar.

The muscle-up is like a pull-up followed by a dip. According to CrossFit, its roughly equivalent in terms of exertion to three pull-ups and three dips. It can take months or more to develop the strength to do it – I’m certainly not there yet. For more info on the muscle-up, and other skills, check out BeastSkills.com.

You are a cyclist in SF and you’ve been hit by a car

Today on my ride home from work, along Fell St. between Divisadero and Broderick, I saw the guy cycling just in front of me get hit by a car which made a sudden left turn, into the bicycle lane, and into a parking lot.





The car was moving slowly at the time, but the guy was going pretty fast, so it was essentially like he rode into the front of the vehicle at a pretty good clip while getting bumped from the side. Myself and a couple of other cyclists immediately came to his aid. Fortunately, he wasn’t badly hurt – his glasses had banged just beneath his left eye so there was some bleeding there, and it looked like he cut his lip – but no broken bones. Of course, he was pretty shocked. The guy who hit him was pretty shocked too. The car driver was – quite pathetically – apologising over and over – as if thats going to make anything better. Nobody seemed to know what to do.

So if you are hit by a car, what should you do?

According to Cyclist Law.com you should do the following:

When involved in a bike accident, call 911 immediately, assume you are injured and DO NOT REFUSE MEDICAL ASSISTANCE you could be in shock or your injuries just may not be apparent.

ALWAYS make sure police are called to the scene and the police take a detailed report.

Make certain the other driver has provided his or her driver’s license, insurance information, license plate of the vehicle driven, and take a description of the driver and the vehicle.

Other resources for bicycle accident reporting and bicycle safety I have found:

San Francisco accident map, a Google Maps mash-up.
Bicycling Street Smarts, an e-book about how to ride safely.
How not to get hit by cars, another bicycle safety resource.
SFBC’s Bicycle Safety page, which contains information about law, safety, etc.