Skip to content

Instantly share code, notes, and snippets.

View carpeliam's full-sized avatar
👋
say hi!

Liam Morley carpeliam

👋
say hi!
View GitHub Profile
def ordinalize(i)
words = ['zeroth', 'first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelth', 'thirteenth', 'fourteenth', 'fifteenth', 'sixteenth', 'seventeenth', 'eighteenth', 'nineteenth']
deca_prefixes = {20 => 'twenty', 30 => 'thirty', 40 => 'forty', 50 => 'fifty', 60 => 'sixty', 70 => 'seventy', 80 => 'eighty', 90 => 'ninety'}
return words[i] unless i >= words.size
suffix = i % 10
prefix = i - suffix
return deca_prefixes[prefix].chop.concat('ieth') if suffix == 0
return deca_prefixes[prefix] + '-' + words[suffix]
end
# Template which configures a generic Rails app with Shoulda, Factory Girl,
# HAML, etc while commiting each step into git.
#
# Make sure you have Rails 2.3rc1 or greater installed and run:
# rails -d mysql -m http://gist.github.com/raw/57458/06345c42a92048e699af3140ccd28bbcd8915bc5/archfear.rb my_app
# Helper methods
def environment(data = nil, options = {}, &block)
options = { :sentinel => 'Rails::Initializer.run do |config|' }.merge(options)
desc "Run with same args as db:fixtures:load, but uses semi-sequential IDs"
task :load_fixtures => :environment do
require 'active_record/fixtures'
class Fixtures
def self.identify(label)
@@id_lookups ||= {}
@@id_lookups[label] ||= @@id_lookups.size + 1
end
end
>> problems.size
=> 99
>> problems.include? "a bitch"
=> false
# 1) Point *.example.com in your DNS setup to your server.
#
# 2) Setup an Apache vhost to catch the star pointer:
#
# <VirtualHost *:80>
# ServerName *.example.com
# </VirtualHost>
#
# 3) Set the current account from the subdomain
class ApplicationController < ActionController::Base
class Group
include DataMapper::Resource
# ... no need to paste everything, right?
has n, :users, :through => Resource
end
class Specialty < ActiveRecord::Base
named_scope :all_by_popularity,
:select => 'specialties.*, count(specialties.id) AS c',
:joins => :stores,
:group => 'specialties.id',
:order => 'c DESC'
end
<% for i in 1..1000 %>
joe_<%= i %>:
login: joe_<%= i %>
email: joe_<%= i %>@example.com
salt: 356a192b7913b04c54574d18c28d46e6395428ab # SHA1('0')
crypted_password: 6480dd200db2719d431c7a25b133887ad8b46551 # 'monkey'
created_at: <%= 5.days.ago.to_s :db %>
activated_at: <%= 5.days.ago.to_s :db %>
state: active
invitation: <%= Fixtures.identify("#{i}_invite") %>