Stupid coding mistakes

Made a really annoying mistake today while writing some code to delete data out of Redis.

The mistake was in the final method keep_keys. Every check to see if a key should be rejected I was adding an element to the flattened_keys array over and over again, causing my deletion to slow down over time. A simple change to memoize the keep keys made the process go from never finishing to, completing in a few seconds.

Clearer text in iTerm

For a while, and since moving to a 4k monitor, text has always looked a bit fuzzy when using iTerm. I just discovered that setting thin strokes to always be on has made a huge difference in the crispness of text.


Books of 2015

This year’s standout books were “The Dark Forest” which was the follow on from last year’s “The Three-Body Problem” and “I am Pilgrim”. “Brain Maker” was a real eye opener into the workings of the gut biome. Sadly most other books didn’t really grab me. I’ve also started keeping a track of books I ended up skimming through.

  • The Tiger that Isn’t (4/1/15 – Statistics)
  • It’s not all about me (24/1/15 – Psychology)
  • Just Fucking Ship (28/1/15 – Business)
  • Story of Your Life and Others (5/2/15 – Fiction)
  • Traction (10/2/15 – Business – Skimmed last 40%)
  • The Mom Test (22/2/15 – Business)
  • Stop Reading Self-Help Books (24/2/15 – Self-Help)
  • The Shell Collector (27/2/15 – Fiction)
  • JFDI (1/3/15 – Self-Help/Business)
  • Smartcuts – Audiobook (10/3/15 – Business)
  • Effective Javascript (Skimmed ~60%) (19/4/3015 – Computing)
  • Servers for Hackers (Skimmed ~ 90%) (20/4/2015 – Computing)
  • How Adam Smith Can Change Your Life (29/4/15 – Life)
  • Better than Before – Audiobook (15/5/15 – Psychology)
  • I Am Pilgrim (19/5/15 – Fiction)
  • The Zen Programmer (10/6/15 – Life)
  • Nikon D610 Experience (22/6/15 – Photography)
  • 31 Days to Overcome Your Fear of Shooting Street Photography (23/6/15)
  • How to Shoot Street Portraits (28/6/15 – Photography)
  • Adobe Lightroom 6 Training (28/6/15 – Photography)
  • The Flash Photography Field Guide (Skimmed ~50%) (2/7/15 – Photography)
  • The Street Photography Composition Manual (4/7/15 – Photography)
  • SEO 2016 (15/7/2015 – SEO)
  • Growing Rails Applications in Practice (17/7/2015 – Technology)
  • Make Love not Porn (3/8/2015 – Psychology)
  • Brain Maker (23/8/2015 – Health)
  • The Dark Forest (7/9/2015 – Fiction)
  • Total Recall (15/10/2015 – Autobiography)
  • Meta programming Ruby (21/11/2015)
  • No More Mr. Nice Guy (9/12/2015 – Self-help)
  • Redis in Action (Skimmed ~40%) (19/12/2015 – Technology)
  • Can you go? (18/12/2015 – Training)

Generating product recommendations in Spree using the Jaccard Index

Being able to recommend products to shoppers is a vital part of any online store. The “Customers Who Bought This Item Also Bought” section can lead to a lot of extra sales if done well. The Jaccard Index is a way of measuring similarity between items. Using some custom SQL we can extract the values we need:

With these values we can then calculate the affinity between sold products:


Generate a random email address in TextExpander with Applescript

Since my last post about generating random email addresses in TextExpander, I’ve move from using Ruby to Applescript to do so. Here is my script which essentially does the same thing.


From West to East

More and more people in the Philippines are trying to live like people in the West. I was surprised to see a lot of people taking up hobbies such as jogging and cycling as well as something I had never seen there before, people walking their dogs. The main things I was aware of though was the shift towards a more Western diet.

Ever since I was young my height meant I stuck out when we would go home to the Philippines, but while there last year (2014) many of the younger generation were very close to my own height. Surprisingly a lot were very fat, if not obese too. There have always been fat people in the Philippines, but it is definitely one step up the scale now. In all the times I have been there previously I don’t think I have ever seen an obese Filipino, but this time I saw quite a few. I can only guess this is down to shifting diet habits.

People are eating a lot more processed foods there now as opposed to home cooked meals. Whether that is the real reason or not for these changes, I cannot say.  Whatever it is though, is not for the good. It makes me think of the great phrase “Overfed and under-nourished”. Already the ailments such as obesity are apparent, and only time will tell if more western health problems arise as well.

Gazing into an endless pool

Reflecting on things is an important counter balance to taking action. It is important to understanding why we do or did things, as well as the consequences they might have in the future. It is easy to fall into the trap of over-reflecting, just as easy as it is to over-act. I definitely fall into the former camp. I spend too much time reflecting on what I have, or have not done, as well as what I want to do in the future. As a result I don’t get enough done and end up paralysed in thought. It’s a vicious circle, as the more you reflect, the less you get done and the less you get done the more you reflect on why you haven’t got things done.

It’s easy to know you need to take action but difficult to actually do. Being self-aware of these issues is the main start to overcoming them. Often times when you catch yourself not doing anything, even just phrasing your thoughts can lead to better outcomes. Instead of thinking “Why can’t I get this task done?”, a better question might be “What would be the least I can do right now to make a start?”. As well as how you break down tasks. A todo list with an item such as “Build new feature X” would be better replaced with an item like “Spend 1 hour on feature X”.

Life is an endless pool that we could spend forever gazing into, looking for answers. But the truth is that all the answers we seek are not there. They are everywhere, all around us, waiting to be found.

Using Typeahead.js without Bloodhound

A great library for adding typeahead support to your site is Twitter’s Typeahead.js. Even better is the excellent Bloodhound suggestion engine which comes with it. Sometimes though if you’re dealing with a remote suggestion engine like Elasticsearch’s completion suggester you don’t need to run remote results once again through another suggestion engine. Bypassing Bloodhound is as simple as hooking your own source function into your Typeahead definition.


What is street photography

Street photography is perhaps one of the most difficult genres to nail down. Wikipedia defines it as:

Street photography is photography that features the human condition within public places. Street photography does not necessitate the presence of a street or even the urban environment. Though people usually feature directly, street photography might be absent of people and can be an object or environment where the image projects a decidedly human character in facsimile or aesthetic.

What does that exactly mean? I spend a lot of time on the street photography subreddit and the submissions amaze me to no end, because they fall so far of the mark of what I consider a street photograph to be. My suspicion is that many take the name “street photography” in a literal sense that it’s a photo taken on the street.

The way I think of street photography is that in essence it has that “a-ha” moment. That striking instant that makes you question and want to know more about what’s happening in the photo. On the surface they appear to be photos of people going about their daily lives, but they tell a deeper story. Perhaps through juxtaposition or even just by being they way they are which might be out of the ordinary.