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
View keybase.md

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:

View gist:3741896
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
View introductin_letterpress_the_model_facory_for_the_lazy_people.md

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.

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'
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]
View gist:7728
def has_children?
self.class.reflect_on_all_associations(:has_many).map { |a| !send(a.name).empty? }.any?
end
View gist:4196
# 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
View README
REST/CRUD conventions from http://project.ioni.st/post/2283#snippet_2283
You can’t perform that action at this time.