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
<% 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") %>
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
class Group
include DataMapper::Resource
# ... no need to paste everything, right?
has n, :users, :through => Resource
end
# 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
>> problems.size
=> 99
>> problems.include? "a bitch"
=> false
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
# 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)
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
@carpeliam
carpeliam / _form.html.erb
Created April 3, 2011 06:42
jQuery template solution for nested forms in rails
<!-- app/views/project_roles/_form.html.erb -->
<div class="projectRole">
<%= form.label :name %>
<%= form.text_field :name %>
<!-- etc etc etc -->
<!-- the JS down below relies on the following two lines being next to each other -->
<%= form.hidden_field '_destroy' unless form.object.new_record? %>
<a href="#" class="removeNestedItem">Delete</a>
module DealsHelper
def render_deals
Deal.all.collect do |deal|
content_tag :div, :class => 'deal' do
image_tag(deal.photo_url)
content_tag :h3, deal.title, :class => 'title'
content_tag :p, deal.full_price, :class => 'full_price'
content_tag :p, deal.selling_price, :class => 'selling_price'
content_tag :p, deal.discount, :class => 'discount'
content_tag :p, deal.store.name, :class => 'store_name'