Skip to content

Instantly share code, notes, and snippets.

View modsognir's full-sized avatar

Jared Fraser modsognir

View GitHub Profile
class Animal
def self.noise=(sound)
@noise = sound
end
def self.noise
@noise
end
def speak
@modsognir
modsognir / gist:10646706
Created April 14, 2014 13:14
cloning a bunch of repos
#!/usr/bin/env ruby -w
require 'json'
repos = JSON.parse(File.read('repos')).map {|e| e['name']}
repos.each do |repo|
puts "=== #{repo}"
`git clone mas:#{repo} ex/#{repo}`
end
@modsognir
modsognir / money regex
Last active August 29, 2015 13:59
Regex the crap out of currency
http://www.evertype.com/standards/euro/formats.html
class Test
%w{one two three}.each do |p|
define_method("#{p}?") { self.wat == p }
end
def wat
"two"
end
# Allows you to do (1) instead of (2)
# 1
Given /^I sign up as a staff member with login "([^\"]*)"$/ do |login|
Cucumber(%Q{
When I go to the sign up page
And I fill in "Username" with "#{login}"
And I fill in "Password" with "password"
And I fill in "Password again" with "password"
And I fill in "Email" with "#{login}@domain.com"
products = Product.where("price = 100").limit(5) # No query executed yet
products = products.order("created_at DESC") # Adding to the query, still no execution
products.each { |product| puts product.price } # That's when the SQL query is actually fired
class Product < ActiveRecord::Base
named_scope :pricey, where("price > 100")
named_scope :latest, order("created_at DESC").limit(10)
end
config.encryptor = :modsognir
h = ActiveSupport::OrderedHash.new
h['one'] = '1'
h['two'] = '1'
h['three'] = '1'
h.find_all { true }
=> [["one", "1"], ["two", "1"], ["three", "1"]]
class Model < ParentModel
include Foo::Bar
extend Bar::Baz
module InternalModule
...
end
default_scope :order => 'id ASC'
module ActiveSupport
module CoreExtensions
module Array
module Conversions
def to_sentence
self.join(' and ')
end
end
end
end