Skip to content

Instantly share code, notes, and snippets.

View danielcooper's full-sized avatar

Daniel Cooper danielcooper

View GitHub Profile
class Code
def initialize(person)
@person = person
end
def make_bugs
"#{@person.name} does some typing"
end
end
@danielcooper
danielcooper / gist:3430097
Created August 22, 2012 22:31
Bit of cache config
backend facebookforcats {
.host = "localhost";
.port = "3000";
}
module HTTParty
def self.included(base)
base.extend ClassMethods
#snip
base.instance_variable_set("@default_options", {})
end
end
@danielcooper
danielcooper / gist:3332108
Created August 12, 2012 14:36
Party hard
class Thingy
include HTTParty
end
@danielcooper
danielcooper / gist:3332095
Created August 12, 2012 14:35
chaining example
class Search
class << self
def where(args)
Search.new(args)
end
end
def initialize(args)
@search_arguments = args
end
@danielcooper
danielcooper / gist:3332092
Created August 12, 2012 14:34
Chaining example
##AR 2
Person.find(:all, :conditions => {:name => "Joe", :is_admin => true}, :limit => 10)
##=> Array
#AR 3
Person.where(:name => 'joe', :is_admin => true).limit(10)
##=> ActiveRecord::Relation
@danielcooper
danielcooper / gist:3332088
Created August 12, 2012 14:33
Config block example
#Usage:
# Awesome.configure do |a|
# a.magic_number = 3
# end
module Awesome
class << self
attr_accessor :configuration
def config
self.configuration ||= Configuration.new
source = context[@attributes['source']] if context.has_key? @attributes['source']
#{{ some_text | truncate: 20, '' }}
def truncate(input, length = 50, truncate_string = "...")
if input.nil? then return end
l = length.to_i - truncate_string.length
l = 0 if l < 0
input.length > length.to_i ? input[0...l] + truncate_string : input
end
{% assign name = 'bar' %}
{% if name == 'bar' %}
{{name}}
{%endif%}