Jan 26, 2008

Setting Up A Shared Bazaar Repository

Currently I'm using a Decentralized Shared Mainline Repository. Here's my recipe...

You will of course need a server that's accessible to everyone.

Create a group for project.

$> groupadd projectname

Create an login for each of the users who will have commit access to the shared mainline.
$> adduser --ingroup projectname username

Create a directory for the repostitory inside the web servers document root
$> mkdir /var/bzr/projectname

Set the project folders group to the project groups name
$> chown :projectname /var/bzr/projectname

Set the project folders permissions
$> chmod ug+rwx,g+s,o+rx,o-w projectname

Now you can push updates
$> bzr push bzr+ssh://hostname/var/bzr/projectname


If you need to provide anonymous access to the repository one way would be to serve it with Apache.
Alias /bzr "/var/bzr"
<Directory "/var/bzr">
Options +Indexes +MultiViews +FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>

This would allow you to do something like this
$> bzr branch http://hostname/bzr/projectname

Jan 18, 2008

Obfuscating IDs in URLs with Rails

There are a number of valid reasons to obfuscate IDs in URLs but it's not a replacement for authentication!

My approach to this problem is to allow the database to assign a normal serial ID, which means I don't have to maintain any extra state or use special database features. Then after it's created I save the obfuscated value of the id which I can use on later lookups.

I use Knuth's integer hash because it ensures there will be no collisions and the full range of values will be used.

In this example I'm using a signed 32 bit integer for the hashed_id because it's supported by all common Rails databases. You could however adjust MAXID to any number of bits you want but then you may have to deal with storage and conversion issues.

Model:

class Part < ActiveRecord::Base
PRIME = 2654435761
MAXID = 2**31-1
def after_create
self.hashed_id = (self.id * PRIME & MAXID)
self.save
end
end

Controller:
class PartsController < ApplicationController
def show
@part = Part.find_by_hashed_id(params[:id])
end
end

Jan 4, 2008

Useful Launchpad Tips

I ran across a useful blog post today that included some useful tips for for using Launchpad that's worth sharing.