Skip to content

Instantly share code, notes, and snippets.

@zacstewart
zacstewart / deploy.rb
Created July 4, 2011 17:41 — forked from uhlenbrock/deploy.rb
Simple Capistrano recipe for Jekyll with Pygments and Compass
set :application, 'zacstewart.com'
set :repository, 'git@github.com:zacstewart/zacstewart.com.git'
set :scm, :git
set :deploy_via, :copy
set :branch, "master"
set :copy_compression, :gzip
set :use_sudo, false
set :host, 'zacstewart.com'
role :web, host
@zacstewart
zacstewart / about.md
Created August 9, 2011 18:08 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@zacstewart
zacstewart / .gitignore
Created August 21, 2011 15:33
My .vimrc
.VimballRecord
.netrwhist
.swp/
gvimrc
vimrc
@zacstewart
zacstewart / gfm.rb
Created April 23, 2012 21:35
GitHub Flavored Markdown (Ruby 1.9 compatible)
require 'digest/md5'
def gfm(text)
# Extract pre blocks
extractions = {}
text.gsub!(%r{<pre>.*?</pre>}m) do |match|
md5 = Digest::MD5.hexdigest(match)
extractions[md5] = match
"{gfm-extraction-#{md5}}"
end
_ = require 'underscore'
module.exports = (robot) ->
class Leaderboard
constructor: ->
robot.brain.once 'loaded', =>
robot.brain.data.leaderboard ?= {}
@games = robot.brain.data.leaderboard.games ?= []
addGame: (winner, loser) ->
@games.push
@zacstewart
zacstewart / clean_users.sh
Created July 21, 2012 22:00
EMI Music Data Science Hackathon data cleaning scripts
#!/usr/bin/env sh
# This transforms the 13 answers to the WORKING column
# into integers 0-12, 5 answers to MUSIC into 0-4,
# normailizes LIST_OWN, and LIST_BACK into integer values
# and drops rows with variations of "16+ hours"
# (loses 2.623031698% of the data)
INFILE=$1
sed -e "
s/\"Employed 30+ hours a week\"/0/g;
s/\"Employed 8-29 hours per week\"/1/g;
@zacstewart
zacstewart / breakfast.md
Created August 9, 2012 20:35
Cherri's breakfast shake recipe
  • ice cream
  • 1/2 cup milk
  • 2 tbsp Ovaltine
  • 1-2 tbsp peanut butter
  • 1-2 raw eggs
  • 1 banana
@zacstewart
zacstewart / anonymous_user.rb
Created October 2, 2012 17:35
Rails Soft Sign-Up
class AnonymousUser < User
attr_accessible *ACCESSIBLE_ATTRS, :type, :token, as: :registrant
def register(params)
params = params.merge(type: 'User', token: nil)
self.update_attributes(params, as: :registrant)
end
end
@zacstewart
zacstewart / zacstewart.pub.gpg
Last active October 13, 2015 11:38
My GnuPG Public Key
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.15 (Darwin)
mQINBFC7ikIBEAC/ps60Orp8iuX2CH3JD/VfjqPVVlqWBh40aa9dayMKTHRCHXLC
hTttTcHKeCsLnvmIHqxCxNBJu18kgX6Vvrc2xFO8KHldFxpQOX2oCVVOrDm7Sfc/
eRk61Ey0KCGQca3gNjlYzWOvtYhvL0yMyA/VLQcBdgm5vlkDFaBzvbRmhUZx2sZ1
nzhW7dyTbGOf6TD101MS3otrVxy3Tx4cm5lBdMxvNwutgqtGy75AElzOHg9zZ6kk
4ZF2Ll76wHSQOgrLShIEu2ymQLoS+VwpZeA4ab4FoP1CqxQd3GYPa5dhe6EakDf8
XH+x3CncV/cO2gDIwqE/lZv2yq004yrHAO4bhia8ndTJboNIQvwJICjJy5WIgU4s
MXs5YUZv8su4T1f95+xSSjEjfI6X2zA4WnekzCLUFfGHkr+KMOKUHRQIRVHOwP/X

Breaking table–model–controller symmetry

A while ago I hit a lull in my skill advancement as a Rails developer. I had long since learned to think of my resources as resources. I did my best to limit my controller actions the basic CRUD methods. I considered the "fat model, skinny controller" mantra to be sacrosanct. But I was still often finding myself going way out of my way to implement otherwise mundane features, for example sending mail after saving an object or adding a routine accept/reject to something.