Skip to content

Instantly share code, notes, and snippets.

View nickhoffman's full-sized avatar

Nick Hoffman nickhoffman

  • Toronto, Canada
View GitHub Profile
module TrueFalseComparison
# Enable TrueClass and FalseClass values to be comparable.
# TrueClass values are valued higher than FalseClass values.
#
# See this article for more info:
# http://grosser.it/2010/07/30/ruby-true-false-comparison-with/
#
# Yes, this is evil monkey-patching. The alternative is much, much worse:
#
# [false, true, false].sort {|a, b| a ? (b ? 0 : -1) : (b ? 1 : 0) }
@nickhoffman
nickhoffman / gist:3015881
Created June 29, 2012 05:01
ElasticSearch: Parent/Child: Find children based on parent properties
#!/bin/bash
# Reset the index.
curl -X DELETE "localhost:9200/test/?pretty=true"
curl -X PUT "localhost:9200/test/?pretty=true"
# Create the parent mapping.
echo
curl -X PUT "localhost:9200/test/user/_mapping?pretty=true" -d '{
"user": {
@nickhoffman
nickhoffman / Configure IRB's prompt for a Rails app
Last active December 15, 2015 09:49
Put each of these in ~/.irbrc
if defined? Rails
# Customize the IRB prompt.
short_env = case Rails.env
when 'development'
'dev'
when 'production'
'prod'
else
Rails.env
@nickhoffman
nickhoffman / run.rb
Last active April 15, 2016 19:09
Code Kata: string splitter
class String
def multiline_split(max_line_length)
self
end
end
puts "foo\nbar\nbaz" == "foo bar baz".multiline_split(3)
puts "foo bar\nbaz" == "foo bar baz".multiline_split(9)