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:
I hereby claim:
To claim this, I am signing this object:
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 |
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.
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 |
export PROJDIR="$HOME/Projects" | |
p() { | |
cd $PROJDIR/$1/ | |
} | |
_projectcomplete() { | |
COMPREPLY=($(compgen -W '$(`which ls` $PROJDIR/)' -- ${COMP_WORDS[COMP_CWORD]})) | |
return 0 | |
} |
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] |
def has_children? | |
self.class.reflect_on_all_associations(:has_many).map { |a| !send(a.name).empty? }.any? | |
end |
# 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 |
REST/CRUD conventions from http://project.ioni.st/post/2283#snippet_2283 |