Redirecting Fun with Lightty

Two of my colleagues were having just a little bit too much fun with my blog, so I decided to have some fun back. Over a period of 10 minutes, they managed to leave 10+ comments. Luckily I have full control over my server, and was able to quickly create my practical joke.

$HTTP["remoteip"] == "123.45.678.910" {
url.redirect = (
    "^/(.*)" => "http://www.urbandictionary.com/define.php?term=annoying+person",
    "" => "http://www.urbandictionary.com/define.php?term=annoying+person",
    "/" => "http://www.urbandictionary.com/define.php?term=annoying+person"
)
}

Notes on Installing mod_tile for Mapnik

I have no idea if these notes on how to install mod_tile will be useful for anybody. The current readme states that you need to edit the source code, but never actually where. Well, this is where, at least until the code can either take switches or can auto-configure itself. This is quite brief, so if you need more details, shoot me an email or leave a comment. I have repeated this process on two Ubuntu 7.10 machines.

  1. Install mapnik as per normal – you may also need to do a…
$ ./bootstrap
$ ./autogen.sh
$ ./configure
$ make
# make install
  1. Install libagg (apt-get install libagg-dev)
  2. Make sure the mapnik library files are /usr/local/lib (libmapnik.*)
  3. Make sure to copy/install fonts and input folders into /usr/local/lib/mapnik
  4. Edit Makefile, change line 27 to where your include files are located
RENDER_CPPFLAGS += -I/usr/local/include/mapnik
  1. Edit Makefile, change line 33 to where your mapnik libraries are (libmapnik.*)
RENDER_LDFLAGS += -lmapnik -L/usr/local/lib
  1. Edit Line 40 of gen_tile.cpp to point to your osm.xml file (that you can verify works with generate_image.py)
static const char *mapfile = "/home/kelvin/mapnik-osm/osm.xml";
  1. Edit line 219 of gen_tile.cpp to point to the correct location of the datasource input.
datasource_cache::instance()->register_datasources("/usr/local/lib/mapnik/input");
  1. Edit line 221 of gen_tile.cpp to point to the correct location of your fonts directory.
load_fonts("/usr/local/lib/mapnik/fonts", 0);
  1. The module will install in /usr/lib/apache2/modules, so mod_tile.conf should read:
LoadModule tile_module /usr/lib/apache2/modules/mod_tile.so

Final note: I think it would be possible to just symlink the lib directory to lib64, although I would expect that could have some undesirable outcomes down the road. However, despite being pretty new code, how do I find mod_tile? Pretty good, actually. I expected more difficulties setting it up, but overall the procedure hasn’t been too bad. I like the approach of creating a module vs. using several middle-layers. So once again, hats off to the OSM crew.

ethX Issues with Xen and Ubuntu

My new guest VMs under Xen seem to be having issues where upon each reboot, the network interface gets incremented by 1. For instance, it starts at eth0, then goes to eth1, then eth2, and eventually ethX. There are two issues to fix: 1) get the count back to 0, and 2) stop it from counting again.

I was able to get them to decrease by looking in the /etc/udev/rules.d/70-persistent-net.rules file and removing all entries.

Next, I was able to prevent this by simply inserting a MAC address to the interface in the configuration. For instance, one of my domU’s has this entry:

vif         = [ 'mac=00:D0:59:83:DC:B5,bridge=xenbr0' ]

Lastly, I made sure (as I would with any server) to create an entry in the /etc/network/interfaces file.

auto eth0
iface eth0 inet static
address 192.168.1.16
gateway 192.168.1.1
netmask 255.255.255.0

Works like a charm.

Installing Mapnik on Ubuntu 7.10

I have managed to install mapnik 0.4, 0.5, 0.5.1 and various SVN releases in-between on Ubuntu. While this isn’t in itself exciting, I think I manage to stumble at every installation. I typically forget to add the flags when building, so, to prevent myself from stumbling again, I’m going to write them out here.

Build mapnik

$ python scons/scons.py PYTHON=/usr/bin/python \
PGSQL_INCLUDES=/usr/include/postgresql \
PGSQL_LIBS=/usr/lib/postgresql BOOST_INCLUDES=/usr/include/boost BOOST_LIBS=/usr/lib

Then install it

$ sudo python scons/scons.py install PYTHON=/usr/bin/python \

PGSQL_INCLUDES=/usr/include/postgresql \

PGSQL_LIBS=/usr/lib/postgresql BOOST_INCLUDES=/usr/include/boost BOOST_LIBS=/usr/lib

Then proceed as normal.

And Yet Another Remodel

I have finally decided to do another remodel of this site. I had a few goals before starting:

  • Use one image
  • Use the YUI-CSS framework
  • Use Django
  • Make it easily extendable

So far, I think I’ve accomplished these goals. The site is easier to read, easy to modify, and has a few new features. More entries to come!

Database Woopsie

I returned to my computer today to notice I had the following error:

(145, "Table './databasename/comments_freecomment' is marked as crashed and should be repaired")

Darn. The solution is quite easy, however:

mysqlcheck -uUsername -pPassword databasename comments_freecomment

Now you know what you already know, you can fix it:

mysqlcheck -r -uUsername -pPassword databasename comments_freecomment

If that doesn’t work, you can try a slightly different method. First, go to the location where your databases are stored on the disk (most likely something like /var/lib/mysql/databasename). Next, stop the database – and try to free up as much memory as possible. Then run:

myisamchk -r comments_freecomment

If that doesn’t work, try to force it:

myisamchk -r comments_freecomment -f

Hope that helps!

GPS on the SkypePhone

Yesterday I was sort of curious if I could use my 3 Skypephone in a pinch if I got lost, which here in Sydney, happens quite often. Luckily 3’s Skypephone has both Bluetooth, and supports j2me apps. Mobile GPS unit, here I come.

The recipe to get maps on your Skypephone is pretty darn easy. You’ll need one dash bluetooth GPS receiver (I have the Qstarz BT-Q1000), TrekBuddy, a TrekBuddy acceptable map (easily downloadable), and one dab computer – but since you’re reading this, I figure you’ve got that part taken care of.

My process is as follows (on Linux): plug in your Skypephone and select “usb storage” on your phone. Drag the TrekBuddy.jar file onto your new mounted drive (mine comes up as KINGSTON). Drag a relevent map downloaded from bandnet.org onto your phone as well. Unplug your phone from the USB, and it will scan for new media. Hit Menu -> My Stuff -> Others and scroll down to treckbuddy.jar – hit Run. Go to your Connectivity settings and turn on bluetooth. Next go to Games and Apps and downloaded apps, start TrekBuddy. Press the key above MENU and select Load Map, and choose the map you uploaded to your phone. Now hit Start. Select the GPS device, and you’re in business!

There are more instructions here and also here.

Size of Uncompressed OSM File

I’ve been playing around with OSM a little lately, and have been meaning to construct my own slippy map. At first I wanted to do it on my VPS – but with rather limited storage, and even more limited memory, there just isn’t a way. Three problems exists: the first occurs when trying to use osm2pgsql to import the OSM file into the database. Current records state that this typically uses 650+ MB, something my 512MB VPS just doesn’t have (although I’m writing some code that might make this possible in the future).

The second problem exists with CPU usage. Processes on my VPS don’t really utilize the CPU much, which means renicing the process doesn’t do a thing. The CPU pegs at 100%, as it is supposed to do, except that the VPS auto-kills processes that stay at 100% for any length of time. Luckily somebody wrote a program called “cpulimit” (apt-get install cpulimit) that will cap the CPU usage for a process.

The last problem that I thought about is what if I could uncompress the file. Would that use less memory to stick it in the database? I searched and searched but couldn’t find an answer to how big the actual .osm file is. I ultimately broke down and decided to spend the 50c it would take to get this all done with EC2, and write some scripts to automate it in the future.

However, since I’ve finally uncompressed the .osm, I can tell you that as of about January 1st, 2008, the uncompressed OSM size is 67GB.

Using Distcc

I’m in the process of working on one of my projects, and the requirement came up to download a fairly large file (4GB). Since I only receive ~20GB/month at my house, I decided to just use my server in the U.S. The next requirement came about needing to compile Mapnik, which I had intended to do on the server at some point anyways, yet I ran into memory constraints.

Good old distcc comes to the rescue. I don’t need to use distcc that often, yet when I do, it is very handy. However, I always forget to set g++ to use distcc as well. So, for when I forget next time…

DISTCC_HOSTS='home'
./configure
make CC=distcc CXX=distcc

Maybe one of these days I’ll write a more in depth tutorial for installing distcc, yet until then, you can peruse the notes I left on my VPS provider’s wiki.

Sydney's Driving Habits

Status: ❌

I’ve heard that Sydney is one of the most liveable cities in the entire world – a statement I would generally agree with. However. whoever made this statement obviously didn’t drive to work every day. I’ve reached the conclusion that one of the biggest (and only) drawbacks to Sydney, is the traffic.

So why is the traffic this bad? I have a few theories. The first theory is that Sydney drivers aren’t particularly cordial. I mean, the road could be ending on the merging lane and drivers still won’t let you in. I’ve literally sat for two blocks in near deadlock traffic with my blinker on, and nobody would let me in. Combine this with the fact that whoever designed Sydney’s roads was drunk at the time (roads that suddenly veer off to one side, other roads that go from three lanes to one, roads that steer around a park causing 20 minute delays, or roads always having a bottleneck whilst crossing the rail tracks, etc.,). This plays a role in how everybody typically drives – they drive very close to each other. I don’t just mean tailgating, it is something else. I’ve been to quite a few cities in the world, and I’ve never seen people drive so close to each other.

This close driving has one serious repercussion: there are accidents every morning. When I list to the radio, I continually hear of several major accidents every day. Now, I can’t stop people from tailgating, nor can I stop the accidents – but what I can do is at least try to plot the bottlenecks around the city. I mean, after driving a route several times you’ll already know the bottlenecks – but I think it would be fun to visualize them.

I’ve already done a fair bit of the research how to technically graph it, although there is still quite a bit more to do. My plan is to use OpenLayersOpenStreetMapMapnik and of course Django to glue everything together. I’ll let you know when I have a prototype working.