Skip to content

Instantly share code, notes, and snippets.

CJ Kihlbom cjse

Block or report user

Report or block cjse

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile

Keybase proof

I hereby claim:

  • I am cjse on github.
  • I am cjse ( on keybase.
  • I have a public key ASCn_Q1ODWZ5ttiayWSbj6iFsczIFbxd6b8DK_CPQ2tXkQo

To claim this, I am signing this object:

View gist:3741896
hash_field :body
hash_field :type { self.class.to_s }
hash_fields :body,
:version => "1.2.0",
:type => -> { self.class.to_s }
def self.hash_field (key, value=nil, &block)
if block_given?
value = block

Title: Introduction Letterpress - the model factory for the lazy people.

Why yet another model factory gem?

In this blog post I will try to explain what my goals are for Letterpress.


As a consultant I have worked on many different Rails projects and most of them use model factories to populate their models with default values. I love to use model factories when writing tests. But I have one concern: I have to learn yet another DSL to be able to populate my models with default values. That feels wrong to me.

View gist:195558
StringTemplater with no tokens
- returns blank string if the given string is blank
- returns a non-blank string unchanged
StringTemplater with one token
- replaces token with empty string if no value in context
- replaces token with value from context
- leaves the rest of the string unchanged
StringTemplater with two tokens
View gist:53878
export PROJDIR="$HOME/Projects"
p() {
cd $PROJDIR/$1/
_projectcomplete() {
COMPREPLY=($(compgen -W '$(`which ls` $PROJDIR/)' -- ${COMP_WORDS[COMP_CWORD]}))
return 0
View gist:32335
path = "/Users/cj/Desktop/prisma.csv"
require 'csv', 'r') do |row|
if @headers.nil?
@headers =
e =
attributes = Hash[*]
@headers.each do |header|
e.send "#{header}=", attributes[header]
View gist:7728
def has_children?
self.class.reflect_on_all_associations(:has_many).map { |a| !send( }.any?
View gist:4196
# by bryan helmkamp with slight modification by chris wanstrath
# from
module GitCommands
extend self
def diff_staging
`git fetch`
puts `git diff origin/production origin/staging`
REST/CRUD conventions from
You can’t perform that action at this time.