2017

Stop forgetting your foreign key indexes in Rails with this simple post-migration script

One of our New Year's resolutions at Peg was to make the site faster. For the most part the site was responsive (requests completed in < 100ms), but certain pages were taking much longer to load than they should - with database queries eating up most of the time....

2016

Quick tip: Set the default controllerAs to vm for .component() in Angular 1.5+

One of the most exciting features in the newly released Angular 1.5 is the new .component() helper method (see Todd Motto's excellent, detailed write-up for a full walkthrough). It's now considered best practice to use controllerAs - a best practice which .component() enofrces. If you don't provide a value for controllerAs it will default to $ctrl....

Signing a CSR with an ECDSA key in Ruby

Let's Encrypt just rolled out support for ECDSA certificates in staging - a move that I think will nudge ECDSA signing more into the mainstream. ECDSA offers higher levels of security at much lower key sizes; as Ivan Ristić explains in Bulletproof SSL and TLS:...

Rails tip – Grouping ActiveRecord objects by day or week using datetrunc

Here's a quick Rails question for you. We have a bunch of Posts in a Postgres DB which we want to order by publication day - but Posts published on the same day should be ordered by a different column: upvotes. (This is basically how Product Hunt does it). We're paginating, so we only care about the first 100 posts. How would we do it?...

Which YouTubers are the most Christmassy?

- blog.peg.co

Retiring two old projects – animate-textshadow.js and CSS floating feedback button

Happy New Year! First of all I'd like to wish everyone reading a wonderful 2016 😁. New years are traditionally associated with new beginnings - clearing out the clutter of the previous year to start afresh. In that spirit, I'm retiring a couple of my old projects animate-textshadow.js and my CSS floating feedback button tutorial. I won't be actively maintaining them anymore, and they are effectively deprecated - i.e. I wouldn't recommend their use going forward....

Peg January feature roundup

- blog.peg.co

2014

Do you need a Computer Science degree to be a developer?

- blog.makersacademy.com

Handling strong parameters in Devise 3.1+

In Devise 3.1+ there's a new way to handle Rails 4's strong parameters. Here's a quick rundown of the change, and how to migrate to the new style. (Background: I wrote the pull request that helped form this feature)....

2013

Better GitHub-style syntax highlighting with Rouge

Update 2016: This tutorial is out-of-date. See the repository for alexpeattie.com and the associated README to see how I do it now....

Cross-domain communication without CORS

In a recent project, I had to send data between two subdomains on a site. Unfortunately, this meant I had to deal with browsers' same origin policy. The canonical solution to this is to set up Cross-origin resource sharing (CORS) , but this is a bit of a pain to do1 - especially if you're only making one or two cross-domain requests - and it isn't supported by some older browsers. Luckily there are some alternatives....

Why you might want to silence console.log

console.log might be the most useful debugging tool in a front-end coder's arsenal. If you aren't using it, go read Mastering Console Logging to see why its so awesome....

2012

Two awesome APIs you probably haven't heard of: SharedCount and RESTMailer

I wanted to highlight a couple of APIs which I've found very useful, but haven't seemed to have gotten much exposure: SharedCount and RESTMailer. I have no connection to these services, I just think they're great!...

How a seaweed expert and a screw-up helped win WWII

Earlier this year I read a surprisingly fascinating history of the Natural History Museum in London - Dry Storeroom No. 1: The Secret Life of the Natural History Museum. One of the best stories in the book recounts how an embarrassing mixup involving a cryptogamist (i.e. algae expert) turned into an unexpected triumph:...

TwilioCon 2012

Earlier this month, I was fortunate enough to be invited by a client to attend TwilioCon 2012 in San Francisco. I'd had some experience working with Twilio already, but I definitely came away from the conference having learnt a lot....

Two quick tips to speed up Rails 3 on Heroku

There are lots of ways to speed up your Rails site, but here are two I see a lot of sites neglecting: gzipping and serving jQuery by CDN....

Teaching computers to rap

Today I was lucky enough to stumble on this fascinating paper by Nguyen and Sa describing how they created an automated rap lyric generator. It's well worth a read....

jQuery gotcha: visibility vs. :visible

Something I ran into today - the behaviour of jQuery's :visible selector (and its sister selector :hidden) is somewhat unintuitive - at least after version 1.3.2. From the jQuery docs:...

GitHub-style syntax highlighting with Pygments

Update 2016: This tutorial is out-of-date. See the repository for alexpeattie.com and the associated README to see how I do it now....

Site redesign

My project for February was a redesign of the site. As well as overhauling the look of the site, I revamped the site's internals – migrating the site from Jekyll to Middleman....

Defining versions in Ruby gems

This post is inspired by a question I answered on StackOverflow a while back, asking about the best way to define the version of a Ruby gem....

2011

Improve JS performance with $.noop

Just a simple tip that you might not be aware of - if you have an empty, anonymous function in your code like this:...

New projects - CSS feedback button & animate-textshadow

It's been a while since I blogged last. Since then, lots has happened in the tech world: we had the S3 apocalypse, the PSN debacle, Microsoft bought Skype, the world bought LinkedIn shares. I've been keeping myself equally busy, and I'm going to be rolling out a bunch of new coolness over the next few weeks....

JustVector Icons update (v1.5)

Last month I released the JustVector Social Icon pack, 100 monochrome vectors for social sites and services. Really, the pack was a selfish endeavour: although there are plenty of social icon packs out there, what I wanted - no frills, full-scaleable vectors for all common sites - was difficult to find. But the feedback I've gotten suggests others have found the icons useful too, and the pack's already clocked up 10K+ downloads....

Working with dates in Git

When working in git, you most commonly trace a repository's history using commits' SHA-1 hashes. To revert to a previous commit, you might write something like this:...

This site is open-source (more info) - here's the source code for this page.