Thursday, December 29, 2011

ShinyField - a placeholder jQuery plugin

A simple jQuery plugin, originally developed for the Mendeley website, to

1) implement consistent HTML5 input (text/password) placeholder hinting behaviour across all major browsers, including IE 7+! (Note that having a placeholder value is optional)

2) apply beautiful CSS3 styling such as border-radius and box-shadow on the inputs. Sorry, IE users will not get those lovely rounded corners.

ShinyField source and download on GitHub

Live demo (html source):



Customization examples

Every look-and-feel aspect of this plugin can be customized via CSS. Here are some common examples:

1) To change the dimensions of the input (default is 292px by 36px, with 10px by 8px "inner padding")

 // JS  
 $("input[name=pretty-text-example1]").shinify({"wrapperId": "example1"});  
 // CSS  
 #example1 { width: 100px; height: 24px; }  
 #example1 input { margin: 5px; width: 90px; font-size: 11px; } /* note that you have to override MARGIN here */  
 #example1 .shiny-field-hint { padding: 5px; width: 90px; font-size: 11px; } /* note that you have to override PADDING here */  

2) To change "in focus" border colour

 // JS  
 $("input[name=pretty-text-example2]").shinify({"wrapperId": "example2"});  
 // CSS { border-color: red; }  

Special thanks to @AndrewOfficer and @subcide, of the Mendeley UX team, for design input and advice.

Wednesday, December 28, 2011

Bullhorn Conversion - Chop and Flop

I have been meaning to swap the dropbar on my commuter singlespeed for a bullhorn bar for a while. Over the festive period, after reading a few articles on the web, I finally decided to buy a £2.50 hacksaw and "chop and flop" the bar, i.e. chop off the "drops" and invert the bar.

Why the chop?

The combination of the old school dropbar and the old school Weinmann brake levers makes braking "on the hood" rather difficult, and I often resort to riding with my palms on the ramps of the bar and using my middle and my fourth fingers to push the suicide levers in order to brake, which is not ideal especially when you need that extra bit of braking power in the rain. As I rarely ride in the drop position when dashing around London anyway, I thought a bullhorn setup which allows me to bring the brakes closer to my normal gripping position would be more ideal.

I could probably have got a brand-new bullhorn bar for just over a tenner, but in this age of insane consumerism, it certainly feels very refreshing to be able to create something new yourself using existing bits, in keeping with a greener ethos. Hence I was very excited to undertake this little DIY project.

How to chop?

The whole process was surprisingly easy (even for someone like me who had never sawed anything!) and only took a couple of hours. The following is a step-by-step guide to how to "chop and flop":

Apart from the usual bike tools, such as allen keys, spanners, screw drivers, etc, all the tools that are needed specifically for this job include a (junior) hacksaw, a roll of tape, some lubricating oil and a bit of sandpaper (or a metal file):

The chromed steel bar and the Weinmann brakes before the chop. Notice the protruding pivot bolts - I managed to remove the suicide levers with no problem with this pair of brakes, and I simply left the bolts sticking out, which is perfectly fine:

Now flip the bar upside down and put it back on the bike. Try out a few positions until you have found the most comfortable hand-gripping point. REMEMBER YOU MUST ALLOW ENOUGH EXTRA ROOM FOR ATTACHMENTING THE BRAKES. Simply mark the exact point where you want to cut the bar by wrapping some tape around it. Remember which side of the tape you want to cut:

If you can clamp the bar against a worktop, good for you! Otherwise, some people suggest sawing the bar with it attached to the bike stem. I simply put it on the floor and started sawing. A couple of tips: 1) put it on top of some cloth/foam to stop your neighbours from wondering about the strange noise 2) frequently drop lubricating oil (or chain oil) onto the contact point to stop the blade from breaking:

Hopefully you will have achieved quite a clean cut. Use a bit of sandpaper to sand down any rough/sharp bits. Now use the removed end to help you mark out the cutting point for the other side of the bar. Again remember which side of the tape you want to cut:


On my 90s Concorde steel frame (Sturmey Archer Stem, Selle Turbo Saddle, Schwalbe Marathon Original Tyre, Vittoria Randonneur White Tyre, and a wine bottle cork bar end plug!)

First impression:

I went out for a 30-minutes ride after the chop, and the new bullhorn bar felt superb. I felt that power transfer was much better especially when I was riding out of the saddle. I was able to really lean on the bar. At the same time, transitioning to a more relaxed riding position by moving my hands closer to the top of the bar was smooth and easy. The brake lever reach is still a little bit too far for my liking, but at least I can readily reach the levers now, and I suspect having some modern brake levers may help.

Sunday, November 06, 2011

A trip to Mercian

Ever since seeing a picture of a Mercian bike on an Internet forum, I have always been fascinated by their beautiful lugged steel frames. A weekend trip to Derby presented an opportunity to visit the home of Mercian Cycles. Mercian Cycles is based in Alvaston, a suburb just south of the Derby city centre. What struck me immediately was that the store bearing the name of these sought-after custom-built frames with such distinguished heritage is very much your local bike shop (albeit a pretty pricy one :) ). Admittedly you are greeted by a wonderful display of Mercian bikes and frames as soon as you step inside the shop, which, after all, was what I personally wanted to see, but it does not seem to be obsessed with Mercian's fame. Instead of finding glossy pictures of Mercians from magazines or coffee table books, you get letters from their satisfied customers. They also sell a huge stock of non-Mercian bikes and accessories, and the man at the till was extremely friendly too.

Not quite rich enough to be a Mercian rider, I am now, nonetheless, the happy owner of a Mercian coffee mug!

Another surprise in Alvaston - an art deco pub (which does £3.75 carvery)

Saturday, September 03, 2011

Redis Pipelining

At Mendeley, we use a mixture of (my|no)sql technologies for handling different types of data. Redis is a key-value store that we use for our user feed and user notification data.

Being an in-memory storage system with disk persistence, Redis has delivered exceptional performance in many of our applications. As the applications grow in complexity, it becomes apparent that network delay acts as the main bottleneck. Redis is a TCP server based on the simple request-response model, which means if you are using a client library, such as Rediska, and executing hundreds of SET commands in one go over a single open socket (maintained over the script's execution), each one of those SETs is going to result in a request being sent to Redis, and a response being expected. Each time, the socket will block until the response can be read. The effect of network delay associated with these request-response actions will simply multiply with the number of commands we try to execute per operation.

One obvious answer to this performance issue is to use MSET to set multiple key-value pairs in one single socket request. (Incidentally, MSET is an atomic command, which may or may not be what you want, depending on your particular usecase.)

But there is a better alternative - Redis pipelining. The idea is dead simple: instead of waiting for a response per socket request, the client simply send through multiple requests before reading the aggregated responses. This hugely cuts down the effect of network delay on operation time. Client libraries like Rediska make using pipelining a bliss. In Rediska's case, one simply has to start a pipeline, invoke the commands on the pipeline (instead of the usual Rediska object), and finally execute the pipeline to send through the batch of commands. Minimal code changes required!

Not surprisingly, the performance gain by issuing 5k commands in a pipeline is remarkable. While I cannot provide you with precise benchmarking data, I can say that connecting from my local machine to a Redis server installed on an ec2 instance, the operation completed in 2 seconds as opposed to 20 seconds without using pipelining.

There are a number of points worth noting (some more subtle than others):

  • pipelining is NOT Redis transactions
  • pipelining does not provide atomicity
  • pipelining really is nothing more complicated than the fact that Redis server is able to queue up responses in memory
  • it is entirely up to the client when to send the requests and when to wait on the responses
  • commands in a pipeline must be independent of each other (as individual responses don't get read till the end of the batch)
  • sending through too many commands in a single pipeline may cause memory issues and potentially socket timeout, so one may want to flush a pipeline after a number of commands (best to do some performance testing)

Or "auto flushing pipeline"....

I created a wrapper class for the Rediska_Pipeline to introduce auto-flushing.

Code snippet of an example implementation of the class:

 /** @var Rediska_Pipeline */  
 private $pipeline;  
 /** @var Rediska */
 private $rediska;  
 /** @var int */  
 private $counter = 0;  
 /** @var int */  
 private $flushThreshhold;  
 /** @var array */  
 private $result = array();  
  * @param Rediska $rediska  
  * @param int $flushThreshhold set as -1 to stop the pipeline from autoflushing  
 public function __construct(Rediska $rediska, $flushThreshhold = 5000) {  
      $this->rediska = $rediska;  
      $this->flushThreshhold = $flushThreshhold;  
      $this->pipeline = $rediska->pipeline();  
  * @return array  
 public function execute() {  
      if($this->counter) {  
      $this->pipeline = null;  
      return $this->result;  
  * Magic method to invoke command calls on the underlying pipeline object.  
  * @param string $name  
  * @param array|null $arguments  
  * @return void  
 public function __call($name, $arguments) {  
      call_user_func_array(array($this->pipeline, $name), $arguments);  
      // OR use other method to invoke command calls if one is concerned about the performance of call_user_func_array  
      if($this->flushThreshhold != -1 && $this->counter >= $this->flushThreshhold) {  
  * @param bool $createNewPipeline  
  * @return void  
 private function flushPipeline($createNewPipeline) {  
      $this->counter = 0;  
      $this->result = array_merge($this->result, $this->pipeline->execute());  
      $this->pipeline = $createNewPipeline ? $this->rediska->pipeline() : null;  


Of course it is always worth considering handling heavy IO operations in an asynchronous manner to guarantee responsive user experience, e.g, either by leveraging a queue system or by using AJAX requests.

Saturday, August 13, 2011

David Starkey on Newsnight

Just days after Mr Nick Griffin labeled the white rioters as wiggers, David Starkey, a well-known British historian, claimed on the BBC Newsnight programme that "the whites have become black" is to blame for the recent riots in England.

There were so many ridiculously misinformed and racist views expressed by Mr Starkey, e.g. his sweeping statement about what he called rap (unsurprisingly, when challenged, his lack of hiphop knowledge was quickly exposed, please Mr Starkey, go and listen to KRS-One, go and listen to Mos Def & Kweli), his rant about Jamaican patois as a "false" language, not to mention his insightful analysis of Enoch Powell's River of Blood speech. The list would go on forever.

What really made my jaw drop was his attempt to justify his view as one based on culture, and not colour. At around 1:55 in the video, he went, "Listen to David Lammy. An archetypical successful black man. If you turned the screen off, so you were listening to him on the radio you’d think he was white". I had to think twice to make sure that I was not interpreting Mr Starkey's remark out of context, but this really is no different from saying, "look I am not a racist - I have a black mate (who happens to be culturally a bit white)".

I don't claim to understand the intricate working of this society, and I certainly do not condone the riots nor the gang culture, but Mr Starkey, I can tell you that one of the undeniable causes of what has been happening is the widening gap between the greater society and the ruling class members - people, I dare say, not too dissimilar to yourself.

Two twitter reactions the following day:

David Lammy:

Nick Griffin:

Wednesday, August 10, 2011

Nick Griffin and the W Word

After four terrible nights of rioting and looting, no doubt most Londoners are reflecting on what has easily been London's saddest chapter in recent history. I came across this tweet (see screenshot) by none other than Mr Nick Griffin, the chairman of the racist British National Party. Yes, I would quite openly label them as racists.

When I saw Mr Griffin using the word "wiggers" in his tweet, I didn't really know whether to laugh or to cry. Is this the voice of the most confused man in Britain?

A riot supposedly kick-started by the death of a black man, spreading like wildfire in predominantly black/multi-racial neighbourhoods in London (I am a proud Lewisham resident myself), what a golden opinion for Mr Griffin to preach his twisted politics. Oh wait, there is a white face caught on camera carrying looted items. Ah, no problem, it is blatantly his black friend's fault that this white person decided to join in. I am just going to tweet about these wiggers. Shame on the blacks (and the wiggers).

Shame on you Mr Griffin (and shame on all you scumbag looters, troublemakers too). This is NOT a race war. This is a class war. We are talking about failure in parenting. We are talking about a failing system. Stop inflicting racial tension. Most Londoners are proud of its cultural diversity.

P.S. Why did Mr Griffin not use the N word? Why not niggers and wiggers? Maybe he is making a very clever point here: why is it socially acceptable to use the word "wigger", but absolutely not the word "nigger"? Umm... perhaps not...

Monday, July 25, 2011

Dunwich Dynamo 2011

Two consecutive punctures only days before the ride was certainly not a good sign. Typically the forecast had been predicting heavy rain after a week of relatively fine weather. But then there is no room for common sense, nor cowardice, on the way to Dunwich.

I bought two rolls of Velox to replace the crappy stock plastic rim tape, which I blame for the two punctures, and hoped for the best as my bottom prepared itself for the next 9 intimate hours with my Brooks Team Pro saddle.

The Dunwich Dynamo is a semi-organised bike ride in the UK where cyclists from all walks of life pedal from London to Dunwich Beach 115 miles away overnight under the glorious July full moon. I arrived in Hackney at 8:30 pm for the 2011 edition of this popular annual event. London Fields for once lived to to its name, after hours of torrential rain. Having collected the coach ticket and the route sheet from outside the Pub On The Park, my friends and I joined the stream of hundreds (or > 1000?) of cyclists in our mass exodus to Essex and Beyond. The initial hour consisted mostly of red-light stops and getting strange looks from motorists and pedestrians. As the number of traffic lights started to decrease (so did the number of roadside street lamps which had been aiding us in our progress) the real adventure began. The fleet of red LEDs along the tree-lined roads out of London was really quite a sight. We started to pick up the pace.

Half an hour cycling into the night, the formidable red line was suddenly interrupted by the flashing light of an ambulance somewhere outside Epping. Unfortunately there was an accident. (which I think was not too bad from what I have read on the internet afterwards) As we rode past, the sight of the participant being stretchered into the ambulance was a stark reminder that any moment of carelessness could lead to grave consequences in such situation.

Past Chelmsford, we reached the half-way point at Sible Hedingham some time after midnight, and stopped for some food. We were extremely lucky with the weather. Despite the downpours during the day, the evening had been completely dry. The brief stop however made us release that the temperature had dropped quite significantly since we started at 9pm. Jacket on.

As the great snake of red LEDs wound its way through the countryside of Suffolk, I found the sound of gear grinding and free wheel clicking oddly soothing. Only the occasional calls of "car" echoing through the peloton to warn riders of coming vehicles reminded us that we were not the only insane people out on the road. Long sections of descents and short sections of ascents were the order of the night, and it was on one of these climbs that I had my share of misfortune. Misjudging the climb, I decided to stay on the big front chainring. I was cranking really hard, even on a big rear cog, until half-way up, I inevitably decided to shift to the smaller front chainring. As a more experienced climber would probably have warned me, the chain came off, and I ended up pedalling into the void. "Oh shit", I went. Somehow I managed to unclip my right foot from the SPD pedal and spared myself the embarrassment of kissing the tarmac. My friends helped me put the chain back on, and we were off into the darkness again.

Apart from seeing a Boris bike (good work!) by the roadside and stopping a couple of times for food and toilet, I honestly could not remember much from the time between 2am and 5am. My tiredness and a slight stomachache (probably from eating too much pasta during the day...) made me wish the whole thing would end soon. The sun started to come out, but I was still feeling cold from the wind that kept on penetrating my windproof. Finally we saw road-signs that seemed to lead us closer and closer to Dunwich, but before we got anywhere near the coast, there was more rough riding in store. A "By Road" at 100 miles leading to Darsham was in pretty bad conditions after the rain. While the guys in mountain bikes were happily rolling through the sand/mud, I was desperately trying to avoid skidding or getting a puncture. That was easily the hardest hour of the whole ride.

As the sun started to warm up East Anglia, my legs started to spin more freely, and I was feeling less miserable. I started to take in the scenery and enjoy the riding more. The old Dunwich city wall was a welcoming sight. At around 7:00am we arrived at the beach. Having congratulated ourselves on finishing the ride, we were quick to get to the breakfast queue. During the breakfast, my mind was still pretty blank from the lack of sleep and the lack of energy in general. We decided to crash out on the beach. Bathing in the warm morning sun, I closed my eyes and immediately fell asleep. The commotion a couple of hours later of people starting to queue up for the return coaches woke us up and it was time to head home.

It was only on the coach when I regained my sense that I thought back about the previous 12 hours. It was simply the strangest thing I had ever done, and no words could ever describe the excitement, the sheer emotional experience of riding through the night with hundreds of people who were there for no other reason than to do something slightly crazy.

I will definitely do it again. Absolutely...

P.S. There are loads of excellent blog entries out there listing tips for surviving the Dunwich Dynamo. One thing I would say to anyone who wants to give it a go is that don't worry if you don't have the latest ultra-light roadbike or if you don't spend all of your leisure time on a bike saddle. Dunwich Dynamo is not a race. Just wear something comfortable and warm, and learn how to fix a puncture (if you don't already). You will be OK!

P.S.S. Big thanks for the Southwark Cyclists for being the driving force behind this excellent event.

Sunday, February 13, 2011

Where has the Thames Path gone?

This weekend, I decided to check out the North Greenwich stretch of the National Cycle Route 1 with my girlfriend for a bit of leisurely (and what I hoped to be scenic) cycling along the Thames, seeing that it is only a stone's throw away from where I live. Starting off from the Greenwich town centre, we were surprised to find that the cycle path came to an early abrupt end as the a property development (Lovell's Wharf) quite literally stood in the way of the Thames Path. After a minor detour, we got back onto the route following the signs down the side of the Blackwall Tunnel Approach (A102). This bit of the route is on cycle path shared with pedestrians on pavement. Unfortunately it was very badly maintained and also full of broken glass. The route finally took us away from the busy A102. However, at this point, the cycle path also degenerated to a sandy dirt track (I believe the area is called Delta Wharf). It was so bad that we had to get off and push the bikes for a couple of minutes. The route did get better afterwards once we passed the O2, but for some reason, another development decided to stand in front of us on Mudlarks Boulevard. By that point, we got so fed up that we turned back and cycled home.

P.S. I have since found a couple of very insightful articles on

See and more on

P.S. I have also found this rather non-informative announcement on the Greenwich Council website: What about a simple map?

Greenwich Council, please look after the Thames Path! It is one of (y)our biggest assets.

Power Grips and CRUD Roadracer MK2

Every now and then, you buy a piece of bike gear and it just works. You don't feel the need to spend hours surfing the net reading product comparisons / reviews trying to convince yourself that it was money well-spent. I have just bought two of these products.

Power Grips

Frustrated by being left behind by fellow commuters who can seemingly accelerate at will in their clipless shoes up Blackfriars Bridge every morning, I want some kind of foot retention on my beater steel singlespeed. I am not a big fan of toeclips and straps as I never seem to be able get the adjustment right. Having come across the Power Grips pedal straps a while ago, I decided to buy a pair of second hand ones from eBay. Each Power Grips strap is essential a big fat piece of laminated strap that goes from one corner of your pedal to the opposite diagonal corner. (Ah yes you do need pedals with toeclip mounting holes on them in order to fit the Power Grips) The idea behind this diagonal setup is that as you straighten up your foot inside the strap, the strap will naturally tighten around it, giving you a firm attachment to the pedal, and they really do work! They are surprisingly easy to get into and out of, and the leverage you get from these things far exceeds that I get from toeclips. They accomodate even my chunky walking shoes (for those miserable rainy days)...

CRUD Roadracer MK2

Feeling much too impatient to wait until good weather to go riding on my new roadbike, I bought the CRUD Roadracer MK2 mudguards from Condor London the other day. I guess, most people, upon opening the box, would be surprised to find that the product looks more like a bit of plastic Airfix kit than a pair of mudguards, and yes installing the mudguards involves "building" them from bits, and it took almost half and hour, but for me that was actually quite a bit of fun! The Roadracer is designed to fit roadbikes with up to 25mm 700c tyres with minimal (as little as 5mm) tyre clearance. The mudguards do not require eyelets, and they are impossibly lightweight. Once installed, they feel pretty firm and do not rattle annoyingly like some metal mudguards do. The MK2 version provides complete coverage for the rear wheel. The rear blade drops all the way down to the seatstay "wishbone". (I had to chop a bit off the bottom with a knife as it was a bit too long for my frame) In additional, it is sculpted very cleverly to stop any water from spraying onto right hand side of the bottom bracket - the chainset area. The really cool bit about the Roadracer is that it comes with little brushes that keep the sides of the guards from touching the tyres, keeping them reasonably centred at all time. I cannot imagine a better set of mudguards than the Roadracer MK2 in terms of coverage on any roadbikes. Last but not least, they sit so snuggly around the wheels that I do not find them ruining the aesthetics of the bike at all. You almost don't notice they are there!

I have not had a chance to see whether it will keep the backside and the bike clean in a proper deluge, but so far I can say it is a piece of really well-designed kit.

Wednesday, February 09, 2011

Who says researchers are humourless creatures?

Now embeddable widgets are available for Mendeley groups too. Click on the Embed link at the bottom of the "About this group" box on any public group pages on Mendeley.

By the way, who says researchers are humourless creatures?

Creatively named research papers is a group in Economics, Philosophy, Psychology on Mendeley.