Rails File Naming Conventions

  • Mar 8, 2023

One of the best things about Rails, that it gets right over so many other frameworks like React, is its Directory Naming Conventions. You can jump into any Rails app written in the last 15 years and no immediately where to go to start exploring. Where's the routes? Database Models? Controllers and Views? Every app keeps them in the same place, so once you learn it, you can easily transfer that knowledge to another project.

Read more

Using Postgres Enum in Rails ActiveRecord

  • Oct 16, 2020

In this post, I will provide some code to make working with an Enum data type in Postgres easier within your ActiveRecord models. Skip to the end for the code, or stick around for some verbose pontificating.

Read more

Using Dry::Container for Dependency Injection

  • May 6, 2020

The point of this post isn't to convince you of the usefulness of Dependency Injection there's been plenty of pixels spilled about it already. Instead, I want to talk about using Dry::Container to alleviate some of the pain points that DI introduces.

Read more

In-Band vs. Out-of-Band: The Advantages of Hypermedia APIs

  • Jul 30, 2016

A good way to look at the advantages of a hypermedia-based API vs an "HTTP-RPC" style one is to consider the differences between "In-Band" and "Out-of-Band" information. A hypermedia API focuses on getting as much information in-band as possible, reducing the burden on clients to deal with changes.

Read more

Let's Encrypt + Route53 + Ruby = Yay!

  • Apr 21, 2016

A few months ago, Let's Encrypt rolled out a feature to verify domains over DNS. Their automatic configuration tool doesn't support all the use cases yet, including my particular scenario: multiple load-balanced EC2 instances behind a single ELB, using Route53 for DNS. I wrote a tool to simplify updating Route53 DNS Records with the challenge, as well as updating the ELB with the resulting certificate. Check out the README and code, or read on for why I wrote it.

Read more

The Conductor Pattern

  • May 1, 2012

A movement has been growing over the last several months to make our Rails applications more object-oriented. One of the most popular recently has been Avdi Grimm's Objects on Rails. In it, he talks about an alternative to the Presenter pattern, which he calls Exhibits (and both of which are subsets of the Decorator pattern). I've been using another form of this, which may or may not be called a Conductor.

Read more

Annoucing ProgressBar

  • Apr 10, 2011

I was working on a script to sync hundreds of thousands of records between two databases, and wanted a simple way to keep track of progress. I couldn't find one that was easy to use and did what I wanted, so I wrote my own. Not much more introduction needed, how about a simple example?

Read more

The Road to Better Authorization

  • Nov 22, 2010

I have several Google accounts: My personal email, Google Apps at my employer, and Gmail for my domain. I use my personal email all the time, and have several Google Docs spreadsheets and letters. Our company uses Google Docs and Sites. Its extremely annoying that switching between these accounts is brittle, and unpredictable. The same situation existed on Github between my personal and the company account, before they added "Organizations".

Read more

Dear Microsoft: Please Do Pinned Menus Like This Instead

  • Sep 25, 2010

With the IE9 betas beginning to come out, Microsoft have introduced an interesting new feature they're calling pinned sites. For more details about how it works, you can check out the Ars Technica preview. Essentially, you put several ms-vendor specific meta tags in the html of your header that describe the menu. The example given on the Ars preview uses this markup:

Read more

About this Blog

  • Jul 2, 2010

After nearly a year on hiatus, I'm finally ready to start blogging again. I have several neat projects I've been working on over the last several months, and I need a place to write about them.

Read more

Your Web Service Might Not Be RESTful If...

  • Jul 20, 2009

The other day, I gave a brief talk about our HTTP Library, Resourceful. After a few minutes of going over the features, it became apparent to me that very few people have taken the time to appreciate the finer points of HTTP. Everyone who calls themself a web application developer needs to take a few hours to read RFC2616: Hypertext Transfer Protocol -- HTTP/1.1. Its not very long, and increadibly readable for a spec. Print it out, and read a few sections when you go for your morning "reading library" break. Unfortunately, a great many people got confused by it, and ended up reimplementing a lot of http in another layer, and thats how we ended up with SOAP and XML-RPC. There's a good parable about how this all went of the rails for awhile, until some people re-discovered a section in Roy T. Fielding's disseration, "Representational State Transfer (REST)".

Read more

Writing DataMapper Adapters - A Tutorial

  • Mar 31, 2009

The adapter API for DataMapper has been in a bit of flux recently. When I submitted my proposal for a talk at MountainWest, adapters were irritatingly complex to write. You just needed to know too much about DataMapper's internals to be able to write one. A week before the conference began, I started a significant effort to re-write the API to make it easier. I succeeded, a little too well; my 30 minute talk only took 15. Since then, I've written a couple more adapters from scratch, and refined the API further. This post will serve as notes on the changes that I've made, and a tutorial on writing adapters.

Read more

DataMapper Echo Adapter

  • Mar 12, 2009

I just wrote a simple adapter that can be used to investigate the DM Adapter API, and debug your own adapter. Its really simple to use:

Read more

A Response to "Database Versioning"

  • Mar 3, 2009

I was just going to post a comment in reply to Adam Wiggins's Database Versioning post, but it ended up being pretty long, so I'll post a response here instead.

Read more

HOWTO - Get a list of a class's subclasses

  • Feb 5, 2009

I recently came across a situation where I had an AbstractClass, an I wanted to know all of the classes that had inherited from it. There were lots of implementations on the web, but that weren't exactly what I wanted, or they used ObjectSpace to get ALL the classes, and see if the interesting one was in its ancestors.

Read more

Ruby Dir.glob bug

  • Jan 20, 2009

To further elaborate on Yehuda's twit:

Read more

DataMapper 0.9.6 released

  • Oct 13, 2008

I just pushed 0.9.6 of dm-core, dm-more and data_objects up to rubyforge, as well as 0.9.8 of extlib. There's several bugfixes that were applied in the runup to merbcamp. This is also preparing for the imminent release of merb 1.0RC1.

Read more

HOWTO: Better JSON parsing when POSTing to Merb Apps

  • Oct 10, 2008

Where I work, we have fairly extensive, JSON-based web services in all out applications. As a quick example, here's what you would get if you were to GET http://config.ssbe.example.com/configurations/90 with the mime-type application/vnd.absperf.sscj1+json:

Read more

HOWTO: Exception Handling in Merb

  • Oct 1, 2008

Our app is very (JSON) web-service heavy, and so having helpful error messages in our web service documents is pretty important. Luckily, Merb makes this, like everything, a metric shitton easier than it is in rails. There are a couple poorly documented things I had to stumble through, so I thought I would write some up on how to do this.

Read more

HOWTO: Getting a sidebar in Merb

  • Sep 16, 2008

In several of my pages, I have a side-bar menu-y thingie. I didn't want to have to rewrite a controller-specific layout each time, but luckily Merb supports something similar to Rails's content_for block that I wrote about earlier. In Merb, its done using throw_content(API) and catch_content(API).

Read more

HOWTO: DataMapper - Setting the default repository for a model

  • Aug 29, 2008

Had to google for quite a while before I was able to find the solution. Essentially, I have a model that I want to always use a different repository than what I #setup in :default. To do that:

Read more

Resourceful - Adding default options

  • Aug 1, 2008

I just commited a change that allows you to specify some default headers to attach to all requests made on a resource. Best shown in an example, I'll use the sample code I gave in my last post:

Read more

Resourceful 0.2.1

  • Jul 31, 2008

I'm pleased to introduce the next release of Resourceful, 0.2.1. This one has tons of bugfixes over 0.2, and is actually being used in production. There's only one real new feature to speak of is prettier logging output. It shows the runtime for requests, the resulting status code, and if it was retrieved from the cache. Some sample log output:

Read more

Announcing Resourceful

  • Jun 30, 2008

Resourceful is an advanced http library for Ruby that does all the fancy stuff that makes HTTP an amazing protocol. I'm pleased to announce the initial release of Resourceful, 0.2. It already has some pretty cool features, with more to come.

Read more

Spec'ing Migrations (A Tutorial)

  • May 23, 2008

I realized I haven't blogged about (IMHO) the neatest feature of DataMapper's migrations yet. One of the more harrowing experiences for me in Rails is upgrading a production server with live data, and hoping your migration handles all the existing data correctly. You can dump the database, and attempt the migration on a clone, and hand-examine the data to make sure it was correct, but that feels very non-ruby-like to me. With the spec groups and matchers available in DataMapper migrations, though, you can spec your migrations and be certain that it will work correctly, and translate all your edge-case data correctly.

Read more

Moving on from Gentoo...

  • May 22, 2008

Updated: I added a few more paragraphs that I had originally commented on in response to Mr. Berkholz's comment.

Read more

I might as well get in on it, too

  • Apr 16, 2008

Modified for zshell:

Read more

MySQL Enterprise

  • Apr 15, 2008

I just came across this link about some new MySQL features will be for Enterprise customers only. The feature they mention here is online backups. I think I'm just going to stop using MySQL for any new projects.

Read more

Rails Logging to Syslog using Logging gem

  • Mar 6, 2008

When using a mongrel cluster, you can either log to a separate file for each mongrel instance, or you can log them all to the same file, but on a loaded cluster, there's a good chance your logged lines will get interleaved and be unreadable. Luckily, there's another way. The new replacement for log4r Logging can take care of this. It has a built-in way of not interleaving the lines, but (I think) its using lockfiles to do so, and if so, that's going to be detrimental to performance. The best solution has been around for 25 years, syslog. And with one of the more recent syslog daemons (syslog-ng, or rsyslog), you can set it up to log your mongrel log wherever you like.

Read more

DM Migrations (now with 100% more helpers!)

  • Feb 12, 2008

Added some helpers to the DataMapper Migrations I've been writing. These helpers just build up some SQL, and feed it into #execute.

Read more

Idealized Migration DSL

  • Jan 8, 2008

There's a discussion in the datamapper group about how to do migrations. I've thrown together an idealized DSL for how the migrations themselves should look.

Read more

Ruby rescues are not slow

  • Nov 27, 2007

I've heard several times that you should avoid exceptions because they are slow. They are in Java, so I think that has given them a bad name everywhere. The only real numbers I could find are from http://www.notsostupid.com/blog/2006/08/31/the-price-of-a-rescue/ . His 'plain' test is also missing the conditional that would also have to be executed (In this case, to make sure 5 is not 0). His post is also 18 months old, so I updated the 'plain' test and re-ran it (Upping the runs to 5,000,000). My plain test now looks like:

Read more

Comcast & Bittorrent

  • Oct 27, 2007

Comcast user? Bummed that they're ruining your bittorrent? No problem. They way the kill your connection is by sending unsolicited TCP reset packets to your bittorrent client, making it think that the person you're downloading from has closed the connection. If you're using a good firewall/router, you can write a rule that will block it. I'm using Tomato firmware for my Linksys WRT54G, and added the following line to my firewall scripts: iptables -A {wan interface} -p tcp --dport {bittorrent port} --tcp-flags RST RST -j DROP This drops all incoming RST packets to your bittorrent client. Now, this even removes the legitimate ones, if your source really does disconnect, you won't know about it. Luckily, the connection will timeout after about 10 minutes anyways, so its not that bad. I've been using this for a couple weeks now, and my bittorrent transfer speeds are back to what they were before Comcast started doing all this.

Read more

Rails tip: Additional content for a layout

  • Oct 22, 2007

If you need to add additional content to your layout, you can have named content_for blocks. Great for including additional page-specific javascript files.

Read more

Rails update_attribute gotcha

  • Jan 26, 2007

Model#update_attribute(:name, "Rando") does not trigger any validations, even on name and just saves it to the database.

Read more