Skip to content

Instantly share code, notes, and snippets.

View bkeepers's full-sized avatar

Brandon Keepers bkeepers

View GitHub Profile
def slow_each(options, &block)
0.step(count(options), options[:limit]) do |offset|
find(:all, options.merge(:offset => offset)).each(&block)
end
end
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?
@bkeepers
bkeepers / gist:12632
Created September 24, 2008 18:45
Script that demonstrates a slight leak in Prawn's table generation code.
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
#!/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')
@bkeepers
bkeepers / section_drop.rb
Created October 17, 2008 18:02
Archives section from http://opensoul.org
<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>
<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>
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
# 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 }
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.
#
#!/bin/sh
connect -H iphone.modem:3128 $@