Skip to content

Instantly share code, notes, and snippets.

foreach($post_params as $key => $value) {
$sanitized_value = sanitize($value);
$regex = '/\<\$' . $key . '\>/';
$template_content = preg_replace($regex, $sanitized_value, $template_content);
}
// lol
def has_permission(name)
(p = permissions.detect{|p| p[:name] == name } ) ? p[:active] : false
end
def has_one_of_permissions(ps)
ps = [ps].flatten
ps.each do |p|
return true if has_permission(p)
end
false
alias push="rake test && git push" # Cheapskate's CI
>> HashWithIndifferentAccess.new.is_a? Hash
=> true
require 'mechanize'
# scrapes Xero for our bank balances and stuff
class XeroScraper
XERO_USERNAME = "xero username"
XERO_PASSWORD = "xero password"
class Account
class String
def jammize
gsub(/\s/, '').underscore
end
end
"My Whatevers".jammize #=> "my_whatevers"
class Time
cattr_accessor :frozen_to
class << self
def now_with_freezing
if @@frozen_to
@@frozen_to
else
# /config/initializers/since.rb
ActiveRecord::Base.class_eval do
[:created, :updated].each do |name|
named_scope "#{name}_since", lambda { |time| { :conditions => ["#{name}_at > ?", time] } }
end
end
~/projects/[project](master) $ git pull
Current branch master is up to date.
~/projects/[project](master) $ script/plugin install git://github.com/technoweenie/relative_time_helpers.git/
Initialized empty Git repository in /Users/nik/projects/[project]/vendor/plugins/relative_time_helpers/.git/
fatal: bad revision 'HEAD'
refusing to pull with rebase: your working tree is not up-to-date
class Array
def detect_index(&block)
each_with_index do |e, i|
return i if yield e
end
end
end