76 Apollo — A Tour of Victoria’s Bicycle Shops

Back in July of 2011 both my and my girlfriend’s bicycles were stolen at the same time. The bicycles were thankfully later returned. Before that happened though we hung posters up everywhere trying to get them back. An nice old couple saw one of our posters, and while they had not seen our bikes, they did have an old one sort-of like mine in their garage that they wanted to sell. The day I arranged to visit them I ended up leaving with not just one but three old bicycles; one was garage kept and clean, the others kept dry but outside and had rusted.

One of the rusted bikes is a green Apollo 10 speed from 1976 with 27″x1¼” tires. The frame on this bike is a massive 62cm. The bike, like almost every other bike in Canada’s west coast from the 60′s-70′s, has a “Fred Deeley Cycles Ltd” badge on the seat tube. Fred Deeley Cycles Ltd of Vancouver was the only importer and supplier of European and Asian bicycles in the province at the time.

The bicycle is made by a parade of Japanese manufacturers. Shifters, dérailleurs, freewheel and gears from Shimano, rims by Araya, cranks from Sugino, and brakes and stem from Taiwanese Dia-Compe. The rear dérailleurs is branded “Shimano 500,” while the front is “Shimano 50.” The brakes are top pull. The rig is either early or cheap Japanese, as the rear gears use a free a freewheel rather than a cassette, and the cranks are cottered. Everything on the bike was made of steel too; the rims, hubs, cranks and even the drop handlebars are steel.

The bike came with a lot of extras: “suicide” brake levers, dynamo and lights kit, chromed fenders, rat-trap rear rack, horn and a plastic Norco cable driven speedometer. The fenders were bent and rusty, the speedometer cable was broken, the horn’s rubber ball busted, but the dynamo still worked. I took all this stuff off as it was mostly useless.

76 Apollo - Original Condition

76 Apollo - Rusty Chrome

76 Apollo - Fred Deeley Cycles Badge

Having been kept outside, all of the chromed surfaces were rusting. Despite this rust issue, the bike seemed to ride well so I sold it to a roommate. He rode for a few weeks until the rear hub started to shrink. The hub was of a crimped-together multiple part body design. Rust had penetrated in between the crimps of the flanges, cups and spacing tube and the forces from cycling had crushed them into each other. The flanges ceased to be parallel and the wheel went way out of true.

I bought the bicycle back from my roommate and decided to rebuild it whenever I had time. After some months I set about the task this past February. When setting in, I decided that both the front and rear wheels were too rusted to be repairable. The freewheel and gears were in good shape, so I took the rear wheel to North Park Bicycle Shop to have the freewheel unscrewed. The hub, rim and spokes were so rusty they warned that it wasn’t safe to ride on… oops. After stripping the bike down I removed as much rust as I could from the frame with a wire brush, steel wool and 5000 grit wet-sandpaper. In the places where bare steel was exposed I used a spray-on clear acrylic to protect the metal.

76 Apollo - Cleaned Frame

 

For the rear wheel I decided to make one from some spare parts I had lying around. I had a wheel with an aluminium rim and crimped hub that had also rusted out in the same way, and a perfect steel Shimano hub from a 26″x1⅜” wheel which I had stolen the rim from for another project. As the rim flanges were the same diameter and distance apart, all I had to do was swap the hubs.

I’m not sure why wheel building isn’t very popular today. I have yet to meet someone who regularly builds wheels. Maybe it’s because a used but decent wheel is usually $25 while a set of 36 new spoke is $28. In either case, it isn’t that hard. One evening of hanging out and drinking beer, and a trip to Recyclistas to borrow their truing stand and replace some bad spoke nipples later, I had a new aluminium rear wheel. While at Recyclistas I also picked up a pair of used pedals and a new chain.

76 Apollo - Rebuild and Trued Rear Wheel

76 Apollo - Rear Rim Detail

76 Apollo - New Rear Hub Closeup

76 Apollo - New Rear Wheel and Freewheel

76 Apollo - New Wheels On

For the front wheel I decide to be lazy and got a used aluminium wheel with a quick-release axle from Bicyclitis. While there I also got a matching new tire for the rear, a used pair of Shimano Atlas stem shifters, and a set of Shimano Dura-Ace cable ties (oh-la-la). To round off my new-parts list I visited three more shops.

From Fairfield Bicycle Shop I bought some Cat’s Eye brand front and rear LED lights. Cat’s Eyes are cheap, so you don’t care if someone steals them, but bright, easy to mount, easy to change batteries, and don’t turn off if you hit a bump (an uncommon feature in the cheap light range.)

From Performance Bicycles I bought black bar tape. They have this faux-leather microfiber stuff with little holes in it like you would see on a tennis racket. I love it, it is neither too firm like plain vinyl, nor too soft like the thick faux-cork.

Finally from the MEC downtown I got a pair of black fender’s. I debated getting a new rear-rack too, but held off as I could always get one later. The fenders were long and had huge mud-flaps, longer than the EVO ones I had bought before. MEC’s bicycle parts selection is surprising. They don’t really do old bicycles, but they do have great racks, panniers, fenders, tires and tubes, all cheaper than at “dedicated” bike stores. Their selection of bicycle tools is also pretty wide and cheap.

After a bit of assembly and tweaking, the photos bellow show the result. This is the first bicycle I’ve rebuilt not to have steel rims. I quite like this bike, it’s rather pretty in my opinion, but then all old road bikes are pretty to me, green is my favourite colour, and I had put 10+ hours into it. It rides very well, and the new chain makes it silent. The Shimano dérailleurs still work very well. In total I visited six bicycle shops/societies when fixing this bicycle, quite the tour, and I still didn’t visit them all. I think it is great that we have so many bicycle shops and societies here in Victoria.

76 Apollo - Finished, Right Side

76 Apollo - Finished, Front

76 Apollo - Stem and Handlebars

76 Apollo - Rear Dérailleur

76 Apollo - Finished Rear Axle

The bicycle is currently not sold, although it is being lent out. If you are in the Victoria area, are between 6′ and 6’3″ tall and need a bike, send me an email.

[Gallery of all photos.] [Directory listing of all photos.]

TrackPointing with UDev

The TrackPoint pointing device pioneered by IBM and found on all ThinkPad laptops is awesome. My laptop only has a TrackPoint for a pointing device and I love it. They take about a week to learn, but once you do you will reach for it constantly, even when you have a mouse. Not having to move your hands is wonderful.

These devices have many configurable parameters to make them more comfortable. Under Linux, TrackPoint device configuration parameters are exposed as files in SysFS. For my system these can be found under /sys/bus/serio/devices/serio1, but that may varry depending on your ThinkPad’s hardware topography, and how much the Linux kernel has changed since this was written.

I like to change the parameters of my TrackPoint to be more sensitive. I used to do this using a script run directly by my system init scripts. This was messy and didn’t work reliably. If only there was some sort of userland system which received device events from the kernel and used them implement policy and userland functionality.

This is of course (part of) what UDev does. The following UDev rule can be placed in /etc/udev/rules.d/ and will initialize your TrackPoint to your preferred settings. (I’m in part posting this here so I can’t lose it.)

ACTION=="add|change", SUBSYSTEM=="input", ATTR{name}=="TPPS/2 IBM TrackPoint", ATTR{device/speed}="150", ATTR{device/sensitivity}="180"

You can set as many attributes as you like using the ATTR{<parameter name>}=”<value>” in the same line. Note that ‘=’ is an action of assignment while ‘==’ is a test of equality used in deciding if the rule applies (just like in C.)

RLWRAP — Making Bad Command Lines Better

GNU Readline is a wonderful library. It is easy to program with, takes care of what is a chore to implement properly and has a user configuration system that means all Readline using applications will have the same customizable behaviour.

I read somewhere that its nickname is “the GNU Trojan Horse.” Being so quick and easy to include in code, if often escapes notice that libreadline is license under the GNU GPL. The GNU-GPL, in contrast with the GNU-LGPL, requires that if libreadline is included your entire project must be licensed with the GPL in order to remain compliant with it.

I think it is for this licensing reason that some software does not use readline. A good example is the command `sqlplus`, the command line interface to Oracle database systems. `sqlplus` is part of the free-as-beer, closed source Oracle database tools. `sqlplus` has less command line features than DOS 5. At least in DOS 5 you could hit F3 to get the previous command recalled, and when you hit the cursor keys it didn’t insert crap into the line. For a command line where you are often trying out different SQL statements, often retrying or recomposing the same query, command history and command editing is a require feature. `sqlplus` is like a go-kart where to steer you have to get off and adjust the wheels with a wrench, then get back on. The task which is the tools main purpose of existence is very tedious to operate.

Enter the program `rlwrap`. `rlwrap` is an executable which places a readline proxy between what it reads from standard input and to what it sends to a command line program. Run a command like sqlplus through rlwrap by typing `rlwrap sqlplus` and bam, you have command line history, editing and filename completion. The best thing is that because `rlwrap` doesn’t modify binary executables to operate you can us it with any program, regardless of licence.

Any command which uses standard input as a command line can benefit; pacmd, xmodmap – both work.

Parallelized Vorbis Transcoding

Often I find myself transcoding large directories of multimedia files from one format to another. Usually a transcode is a single-threaded operation (not so for x264, but we’ll ignore that for now.) It’s rather inefficent to run only one transcode command at a time on a machine with multiple CPU’s as while the transcode with consume all of the CPU time of one of the processors, the remaining processors will be idle.

To use all processors at once we need to run jobs in parallel. Thankfully a tried and tested tool for building things based upon input things a rules with parallelization support already exists: the `make` command. Using make we can transcode as many files at once as we want.

There’s one catch though, Make is a little bit blind when it comes to files which have spaces in their names. I was surprised by this, but I couldn’t find a good way to escape spaces in Makefile syntax. As most media files contain many spaces this was a problem.

Undeterred, I came up with a way around the space problem; Create a symbolic link for each source file that is Make friendly, run Make and then rename the outputs back to something useful and delete the symbolic links.

The following script is the result. This script converts all the audio files passed as arguments to audio files in the Ogg Vorbis format. The actual transcoding is done by the `avconv` from libAV. I use libAV as it accepts many different input files, and it also converts the metadata when transcoding. The script is pretty generic, and it should be possible to easily change it to convert to formats other than Ogg Vorbis.

http://art.ified.ca/downloads/make-vorbis.sh

Quickly Changing Display Outputs

Please ignore the messy deskMultiple-monitor support for X11 has greatly improved from when I started using it. For starters, you no longer have to edit a root-owned text file and restart your Xserver. Now we have the X11 RandR 1.2 extenstion and you can used use the command line on-the-fly or one of the many GUIs to change your output configuration. (If you don’t think this feature is that amazing, fair enough.)

All the major desktop environments have GUIs for display output configuration. Many times these desktop environments attempt to set output configuration at login. My primary computer is a laptop. At home I have a dock with an external monitor. Thus, 90% of the time my display output is in one of the two configurations: single headed laptop panel, or dual-headed laptop panel and external monitor. All the functionality I require is to toggle these modes. In Windows one can use the keystroke Super+P to quickly do so. In Gnome, whatever key generates XF86Display does this as well (if the gnome-settings-daemon xrandr plugin is enabled, which it is by default.)

The catch is that sometimes Gnome’s display output applet gets things wrong, or annoyingly my hardware likes to the generate the XF86Display keystroke when pressing Fn+F7, Dock Eject, Lid Open, Lid Close… etc. This causes my display configuration to change when I shut the lid (annoying), put the machine to sleep (annoying) or when I eject it from my dock (annoying if it didn’t notice that the external monitor isn’t there anymore.) I often find myself going to the command line and doing my output configuration manually.

Then a thought occurred; since I really only use two xrandr commands, there has to be a way to automate the process. One shell script plus Zenity later and this is the result:

#!/bin/bash
# multiple-monitors.sh: Quick-and-easy xrandr(1) arguments picker.
# (c) 2012 Arthur Taylor Permission is granted to any person to use, copy,
# modify, merge, publish, distribute, sublicense, and/or sell this script.
# This script is provided "as is", without warranty of any kind.

ICON="/usr/share/icons/gnome/48x48/devices/video-display.png"

XRANDR_COMMAND[0]=" --output LVDS1 --mode 1440x900 --output VGA1 --off"
XRANDR_COMMAND[1]=" --output LVDS1 --mode 1440x900 --output VGA1 --mode 1280x1024 --right-of LVDS1"
XRANDR_COMMAND[2]=" --output LVDS1 --off --output VGA1 --mode 1280x1024"
XRANDR_COMMAND[3]=" --auto"

TO_RUN=`zenity --list --width=640 --height=240 --window-icon $ICON --title="XRandR Settings" --text="Pick (or edit) an XRandR configuration:" --column="command" --hide-header --editable "${XRANDR_COMMAND[@]}"`

if [ "$TO_RUN" != "" ]; then
    xrandr $TO_RUN
fi

All this script does is take chose text from the chosen list entry and pass it as arguments to the xrandr command (see xrandr(1) man page.) I know this isn’t to most user-friendly method of changing display outputs, and it doesn’t provide failure feed-back, but is quicker than opening a terminal and typing it from scratch.

If you use Openbox, then a keboard shortcut for can be done by simply adding the following to your rc.xml keybindings section:

<keybind key="XF86Display">
  <action name="Execute">
    <execute>bash /the/path/to/multiple-monitors</execute>
  </action>
</keybind>

Linux Console K_OFF Mode in X.org

A patch I submitted to the xorg-devel mailing list marks the end of the K_OFF story described in my previous post <link>. Almost a year later and the xserver handler to vacuum away needless buffered key events, preventing a kworker kernel thread going nuts, is no longer needed. Shortly after it was reviewed and pulled into X.org 1.12-rc1. The commit is fairly small: ff891bbf68caefc22cabb541b6b56af086ac2280.

On a whole, I’m proud to have contributed to two major open source projects, the Linux kernel and the X.org Xserver, albeit only two small patches. During the process I learnt a lot about how F/OSS projects organize themselves and how to communicate with developers and project leaders. I would like to state that the responses I got back from both projects were patient and helpful, and on the whole the process, while a learning experience, was quite easy.

Specifically, I now know about git-format-patch and git-send-email. Also useful to know is that you can setup Git to send through Google’s SMTP servers if you have a GMail (or a GMail based domain email) account. The settings (for the record so I don’t lose them) are:

sendemail.smtpserver = smtp.gmail.com
sendemail.smtpserverport = 587
sendemail.smtpencryption = tls
sendemail.smtpuser = <your Google domain account>

Linux Virtual Terminal Keyboard Mode “Off” Patch

Last December I noticed a strange problem with my Linux system. Every once in a while I would experience about 1000 wakeups/second, a condition that would persist until I restarted my Xserver. These wakeups seemed pointless, failing to use more than 1% CPU usage, but none the less would cause it never to enter lower sleep states, and as this is on a laptop, eat more battery power. I was confused as my friend had similar hardware to mine, but failed to experience the intermittent wakeup problem. A little bit of investigation revealed that this was caused by the kernel tty-layer helper workqueue named “flush_to_ldisc” spinning in an infinite wake up, do no work and reschedule loop. More investigation showed that the loop was caused by my non-standard Xserver configuration not enabling a workaround of an old kernel behaviour.

Previously the Xserver on Linux received its keyboard events by reading from the virtual terminal device. The Linux console works by having a range of virtual terminals, only one of which is connected to the actual console at a time. Each VT has its own input and output buffers and also maintains its own state. The way that keyboard events are handled in the VT is called the keyboard mode. The normal keyboard mode, the one used by a text console, is translate mode, in which the kernel translates scancodes to characters, handling special keys and buffering the rest in the VT. As the Xserver does its own keycode handling and translation it uses raw mode in which raw key up and down events are buffered in the VT.

A new way to handle input devices, the Linux Input Subsystem, became the input base for kernels since 2.5. This subsystem, among other things, exposes the individual input devices to userspace as individual character devices. The X.org Xserver by default now only uses the input-evdev driver to get all keyboard input directly from the input subsystem rather than through the VT. This is great except for a few, shall we say growing problems. First, if the virtual terminal’s mode isn’t set away from translate, special keys are still handled by the kernel, causing ctrl+c to kill the Xserver and other shenanigans. The second problem is that while the Xserver opens a VT, it no longer reads input from it. Every key press gets buffered in the VT and as nothing reads from it, eventually overflows.

The infinite work queue I witnessed was caused by the VT input buffer trying to flush new key events when full.

The first problem I listed with fixed in the Xserver by setting the current VT to always be in raw mode [1]. The second problem was fixed in most cases by setting up a separate task to call flush on the VT input buffer whenever stuff appeared in it [2]. The Xserver would only do this if the server option “AllowEmptyInput” was true, in which case the Xserver knew that input-kbd wouldn’t be in use. If AllowEmptyInput was false but input-kbd wasn’t used the input buffer would fill up. This latter configuration was what triggered the bug for me.

All of this seems rather hack-y and sub par. Surely their should be a way to simply disable the VT input buffer? This being open-source, I took it upon myself to fix the issue. The simplest way would be to create a new console keyboard mode called “off” in which both kernel special keys are ignored and the input buffer remains empty.

My first try was to deregister the tty layer’s input subsystem handler if the current terminal’s keyboard was in off mode. This solution is nice in the sense that it stops a lot of redundant code from being executed per keyevent at the source. Unfortunately there was a complication with shift (or modifier in X11 parlance) keys and shift states.

The second try simply returns early before key events are buffered or special keys are handled. This solution was cleaner, always worked, and only involved nine lines of changes.

After testing the different situations and using it for a month and a bit I decided to try and get the changes into the main kernel tree. A few emails and two weeks later, boom, my patch was accepted by Greg KH into the tty-next branch [3], then pulled into the linux-next branch awaiting the next merge window for linux 2.6.39. The whole affair was quite easy and satisfying. The next step now is to write up a more formal patch for the X.org Xserver. The changes to the Xserver are quite minimal but will require that the updated kernel headers to be installed at compilation time.

[1] X.org X server commit 446d9443cea31e493d05c939d0128a8116788468
[2] X.org X server commit d936a4235c9625bd41569cef3452dd086284e0d7
[3] Linux tty-next commit 9fc3de9c83565fcaa23df74c2fc414bb6e7efb0a

Thinkpad BIOS Hacking

In November I had to take my Thinkpad in for servicing. Unfortunately the wifi card I had in it wasn’t supposed to be there by warranty, and further was hacked into the wrong slot with a piece of tape over one pin to keep the BIOS happy. After I got my system back (three 3 business days later!) it seemed like the perfect chance to hack the BIOS to make it get along with my wifi card. I decided to document my efforts. Here is the result.