Self-validating Ruby objects with ActiveModel Validations

I'm importing lots of CSV restaurant inspection data with Ruby, and I need to make sure the cleaned up data matches the spec. For example, a violation must have a business_id and date. It can optionally have a code and description. My goal was to be able to write a class like this: ...and it would … Continue reading Self-validating Ruby objects with ActiveModel Validations

Python project organization, circa early 2015

The best, current guides I've found Python Packaging Authority's tutorial and sample project Cookie Cutter project templating system, specifically cookiecutter-pypackage Open Sourcing a Python Project the Right Way, and Supercharge Your Python Developers by Jeff Knupp It's hard to find current best practices for organizing a reusable python package. I'm starting a new project to get the world's … Continue reading Python project organization, circa early 2015

Degrees of freedom: Four valid ways to write degrees Fahrenheit in HTML

I was working on my startup's food safety score web app, writing code to clean up imported text like, DELI DISPLAY COOLER HOLDING CREAM CAKE AT 44.6F BUT LOWER CORNER OF UNIT HOLDING FOODS @ 39F We decided to make this as readable as possible without changing the content. And so, the finished text should have improved capitalization, punctuation, … Continue reading Degrees of freedom: Four valid ways to write degrees Fahrenheit in HTML

Linode vs. DigitalOcean: back to Linode for me

DigitalOcean doesn't give their first-line support people the necessary tools to diagnose their own system problems. And so a two-day outage becomes possible. The night before Christmas, I was scrambling to get my site back up On the afternoon of the 24th, my New Relic monitor told me that weblaws.org (now public.law) was offline. Ugh. … Continue reading Linode vs. DigitalOcean: back to Linode for me

What’s not a violation of the Law of Demeter

The Law of Demeter: "Use only one dot", or "an object should avoid invoking methods of a member object returned by another method." But when would this not be a violation? Buried within a C2.com wiki page is this excellent exchange: Trying to come up with a more simple (non-foobar) example, is this correct? currentPerson.Account.Deposit(500) … Continue reading What’s not a violation of the Law of Demeter

Yes, Rails does support case-insensitive queries

They're unfortunately just a little buried and a little undocumented. And so conventional wisdom is that Rails doesn't do case-insensitive finds. But in fact it does: Example 1: Find all the statutes whose name begins with texas, case-insensitively: Example 2: Same query, using the excellent Squeel gem which makes this a little nicer: Results: Both examples generate … Continue reading Yes, Rails does support case-insensitive queries