Writing Long Numbers in Ruby

I just found out that if you need to write a long number in Ruby, you can use underscores instead of commas. For example, you could write one million like this:

1
1_000_000

I find this a lot more readable than:

1
1000000

Pretty nifty.

Find Duplicate Rows With PostgreSQL

What if you need to find all the duplicate rows in a Postgres table containing people? This can be a little difficult, especially if you have separate first_name and last_name fields. TLDR; Here’s a query you can use below:

1
2
3
4
5
6
SELECT first_name, last_name
FROM people
WHERE CONCAT(first_name, ' ', last_name) IN (SELECT CONCAT(first_name, ' ', last_name) AS fullname FROM people)
GROUP BY last_name, first_name
HAVING COUNT(*) > 1
ORDER BY last_name DESC

Zero Downtime Deployment

As you scale software, it becomes less acceptable for your site to be down or slow after you roll out a change. And yet, your app generally needs to reboot after you push your change, and depending on the size of your stack, this could take a while.

I ran into this problem in my work and here’s how I solved it. Or at least part of it.

Replacing Google Voice

Google offers a “free” service called Google Voice. It allows you to:

  • Route a single number to multiple numbers. If you change cell phones, you can just route your voice number differently, no need to tell all your friends.
  • Get transcripted voicemails
  • Block numbers

This is great. I currently use it. However, with freak legislation like CISPA on the horizon, it’s starting to look a little less wise to trust Google with all that data.

Principles of API Design

As a developer who has written a few APIs, and not the greatest ones either, I thought it was about time I recorded the things I’ve learned from maintaining APIs in the wild.

Code Reviews & Automated Testing

You need to automatically test your code. This is the first step toward having any kind of quality assurance when multiple people start committing to your codebase.