This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Foo | |
def self.included(base) | |
class << base | |
attr_accessor :bar | |
end | |
end | |
def set | |
self.class.bar = "hello there" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Want to give your users nice referral URLs, like http://www.service.com/?r=2ab3 ? | |
# | |
# A fast and easy 1-1 method is to use base-n encoded numbers. | |
# | |
# For instance, encode the user's id in base 36. In Ruby, this is easy: | |
# > 272927.to_s(36) | |
# => "5ulb" | |
# | |
# To get the base 10 id back again is just as easy: | |
# > "5ulb".to_i(36) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: | |
# ruby bulk_domain_generator.rb word [word...] | |
suffixes = ['able','ac','acity','ade','age','aholic','al','algia','an','ance','ant','ar','ard','arian','arium','ary','ate','ation','ative','cide','cracy','crat','cule','cy','cycle','dom','dox','ectomy','ed','ee','eer','emia','en','ence','ency','ent','er','ern','escence','ese','esque','ess','est','etic','ette','ful','fy','hood','ial','ian','iasis','iatric','ible','ile','ily','ine','ing','ion','ious','ish','ism','ist','ite','itis','ity','ive','ization','ize','less','let','like','ling','log','ly','ment','ness','oid','ology','oma','onym','opia','opsy','or','ory','osis','ous','path','pathy','phile','phobia','phone','phyte','plegia','plegic','pnea','sect','ship','sion','some','th','tion','trophy','tude','ty','ular','uous','ure','ward','ware','wise','y'] | |
i = 0 | |
ARGV.each do |a| | |
suffixes.each do |b| | |
i += 1 | |
puts "#{a}#{b}.com" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Usage: | |
# gitdb copy | |
# Copies the current development database into db/branchname-development.sqlite3 | |
# gitdb | |
# Copies the db/branchname-development.sqlite3 into the default db/development.sqlite3 | |
branch = `git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'`.gsub('* ','').strip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In your devise.rb configuration file, set the bcrypt stretches to 1 in your test environment: | |
config.stretches = Rails.env.test? ? 1 : 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'redis' | |
class Redis | |
alias :__flushall :flushall | |
alias :__flushdb :flushdb | |
def flushall(confirm=false) | |
if confirm | |
__flushall | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PATH=$PATH:/Library/PostgreSQL/9.0/bin/ env ARCHFLAGS="-arch x86_64" gem install pg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading development environment (Rails 2.3.2) | |
>> class Z < User; end | |
=> nil | |
>> User.subclasses | |
NoMethodError: protected method `subclasses' called for #<Class:0x22ce974> | |
from (irb):2 | |
>> User.send(:subclasses) | |
=> [Z(id: integer, email: string, crypted_password: string, salt: string, created_at: datetime, updated_at: datetime, remember_token: string, remember_token_expires_at: datetime, activation_code: string, activated_at: datetime, state: string, deleted_at: datetime, editor: boolean, has_promise: boolean, reset_code: string)] | |
>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[14:04][ian@ian-terrells-macbook-pro:~]$ ruby --version | |
ruby 1.8.6 (2008-08-11 patchlevel 287) [universal-darwin9.0] | |
[14:04][ian@ian-terrells-macbook-pro:~]$ irb | |
>> class X | |
>> end | |
=> nil | |
>> class Y < X | |
>> end | |
=> nil | |
>> X.subclasses |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fairish | |
def initialize(probability, unfair_low, unfair_high, min_rolls) | |
@probability, @unfair_low, @unfair_high, @min_rolls = probability, unfair_low, unfair_high, min_rolls | |
@rolls, @hits = 0, 0 | |
end | |
def fire! | |
hit = if @rolls >= @min_rolls && observed_probability > @unfair_high | |
false | |
elsif @rolls >= @min_rolls && observed_probability < @unfair_low |