Writing
Notes on building software — the decisions that age well, the ones that don't, and what I learn in between.
-
How to Recover a Mistakenly Deleted Branch
Workflow git checkout -b newbranchname do some work and commit changed git checkout master git branch -d newbranchname doh... i meant to merge first Fortunately, you can easily recover from this...
-
Aliasing Attributes in Ruby on Rails
Alias an attribute with alias\attribute method. The first argument is the name for the new attribute, while the second argument is to identify the attribute that is already defined.
-
Rails 3 Config Auto Load Paths in Application.rb
In Rails 3 files in lib/ are no longer loaded by default. It's a snap to auto load these classes by adding the following line to config/application.rb This is commented out around line 16. Either...
-
How To Get A List of All Registered Mime Types in Rails
When mime types are registered they are placed in a hash constant EXTENSION\LOOKUP in the module Mime. For reference, the file with the relevant code is in...
-
Git Feature Branch Naming Strategy
There are only two hard things in Computer Science: cache invalidation and naming things. -- Phil Karlton Typically, we have three main branches at any given time in a project lifecycle. Master is...
-
My First Ruby Gem: Hashed_Attributes
I just wrote and released my first Ruby Gem, Hashed Attributes https://rubygems.org/gems/hashed\attributes. It is a very simple ActiveRecord extension for saving variables through a serialized...
-
Rails Send_File in Production Delivers an Empty File
If you're running Rails in production it will by default be configured to let apache or nginx send files for you. If you're handling file downloads yourself with send\file you will notice that the...
-
Git Untrack Already Tracked Files
To remove files that are currently being tracked by git, you have to remove them from the "cache". Note, doing this will NOT delete the file on your local machine. It will still be there but not be...
-
Rails Find All by Birthday: How to Find Upcoming Birthdays with ActiveRecord
There are a few ways to solve this problem. However, I think the easiest is to cache the day of the year that the user is born on as an integer. If stored alongside the timestamp we can quickly get...
-
Git: How to Delete a Branch with an Invalid Name
If you've named a branch beginning with two dashes "--", you're sort of in trouble because git interprets your branch name as a switch/flag. You can skip switches all together by supplying two...
-
How to Remove Your Last Git Commit
Remove your last commit (if you haven't pushed yet) To see changes that have been committed and their position in HEAD And to undo your previous reset and advance the cursor to the reference...
-
Backup and Rotate MySQL Databases Simple Bash Script
Make a directory ( it can anywhere ) called baks/mysql mkdir -p /baks/mysql Create a file (it can be anywhere) called /root/mysqlbackups.sh and put this script in it !/bin/bash modify the following...
-
Ruby Rand Range
I assumed that rand would take a range as an argument. Something like rand(10..20), generating a random number between 10 and 20. Seems like you'd do this fairly often when working with random...
-
Link to jQuery Source from Google's CDN
https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js That is the link to the jQuery source hosted by Google on their CDN. It's probably already cached on client machines so it should be...
-
Simple String Concatenation of a Collection Written as a Helper for Rails
At Railsconf last week I took Greg Pollack's online course Rails Best Practices. The interface is gorgeous and the instructions are excellent. One of the lessons involved taking a partial and...