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
def slow_each(options, &block) | |
0.step(count(options), options[:limit]) do |offset| | |
find(:all, options.merge(:offset => offset)).each(&block) | |
end | |
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
def test_invalidate_tree | |
r1 = Category.create | |
r2 = Category.create | |
r3 = Category.create | |
r4 = Category.create | |
nodes = [r1, r2, r3, r4] | |
r2.move_to_child_of(r1) | |
nodes.each(&:reload) | |
assert Category.valid? |
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 'rubygems' | |
require 'prawn' | |
pid = fork do | |
loop do | |
data = [['1', '2']] * 20 | |
headers = ['a', 'b'] | |
Prawn::Document.generate("leak#{Process.pid}.pdf") do | |
table data, :headers => headers |
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 | |
# Generate a rails app (using EDGE rails), set up a git repo for it, and install common plugins | |
# | |
# USAGE: $0 some_app_name | |
# | |
# Adapted from http://github.com/foca/utility_scripts/ | |
# Released under a WTFP license (http://sam.zoy.org/wtfpl/) | |
RAILS_DIR = File.expand_path('~/.rails') |
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
<table class="archives"> | |
<thead> | |
<tr> | |
<th class="month"></th> | |
<th class="month">Jan</th> | |
<th class="month">Feb</th> | |
<th class="month">Mar</th> | |
<th class="month">Apr</th> | |
<th class="month">May</th> | |
<th class="month">Jun</th> |
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
<table> | |
<% @parties.weeks.each do |week| %> | |
<tr> | |
<% week.days.each do |day| %> | |
<td> | |
<ul> | |
<% day.each do |party| %> | |
<li><!-- party info here --></li> | |
<% end %> | |
</ul> |
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 Section < ActiveRecord::Base | |
has_many :articles, :order => 'position' | |
end | |
class Article | |
default_scope :order => 'published_at DESC' | |
named_scope :by_author, :order => 'author' | |
named_scope :by_position, :order => 'position' | |
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
# Thoughts on a backend-agnostic search plugin | |
Scour.define Model do | |
backend :ferret # or :sphinx / :solr | |
index title, :sortable => true, :boost => 1.0 | |
index content, author_id, created_at, updated_at | |
index author.name, :as => :author, :sortable => true | |
index first_name, last_name, :as => [:name, :fullname] | |
index tags.name, :as => :tags | |
index minor { author.age < 18 } |
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 File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
# | |
# This excercises the full set of migrations for your Rails app. | |
# It proves: | |
# - After full migration, the database is in the expected state, including: | |
# - All table structure | |
# - Default data (if any) | |
# - Full downward (version 0) migration functions correctly. | |
# |
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
#!/bin/sh | |
connect -H iphone.modem:3128 $@ |
OlderNewer