Skip to content

Instantly share code, notes, and snippets.

View cjse's full-sized avatar

CJ Kihlbom cjse

View GitHub Profile
REST/CRUD conventions from http://project.ioni.st/post/2283#snippet_2283
@cjse
cjse / gist:4196
Created August 6, 2008 09:22 — forked from defunkt/gist:4169
# by bryan helmkamp with slight modification by chris wanstrath
# from http://www.brynary.com/2008/8/3/our-git-deployment-workflow
module GitCommands
extend self
def diff_staging
`git fetch`
puts `git diff origin/production origin/staging`
end
def has_children?
self.class.reflect_on_all_associations(:has_many).map { |a| !send(a.name).empty? }.any?
end
path = "/Users/cj/Desktop/prisma.csv"
require 'csv'
CSV.open(path, 'r') do |row|
if @headers.nil?
@headers = row.map(&:to_sym)
else
e = Employee.new
attributes = Hash[*@headers.zip(row).flatten]
@headers.each do |header|
e.send "#{header}=", attributes[header]
export PROJDIR="$HOME/Projects"
p() {
cd $PROJDIR/$1/
}
_projectcomplete() {
COMPREPLY=($(compgen -W '$(`which ls` $PROJDIR/)' -- ${COMP_WORDS[COMP_CWORD]}))
return 0
}
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
@cjse
cjse / introductin_letterpress_the_model_facory_for_the_lazy_people.md Yet another fixture replacement model factory gem - Introducing Letterpress

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.

No DSL

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.

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

Keybase proof

I hereby claim:

  • I am cjse on github.
  • I am cjse (https://keybase.io/cjse) on keybase.
  • I have a public key ASCn_Q1ODWZ5ttiayWSbj6iFsczIFbxd6b8DK_CPQ2tXkQo

To claim this, I am signing this object: