Skip to content

Instantly share code, notes, and snippets.

# Here are the pertinent equality methods in the Space class. You can view the whole thing here:
# http://github.com/siannopollo/joshua_son_of_nun/tree/master/lib/joshua_son_of_nun/space.rb
def to_s
[row.to_s + column.to_s, orientation].compact * ' '
end
alias_method :inspect, :to_s
def ===(klass)
self.is_a?(klass)
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe SessionsController do
before do
@user = User.new
@user.id = 10
@user.stub!(:save).and_return(true)
User.stub!(:authenticate).and_return(@user)
end
class Request < ActiveRecord::Base
state_machine :state, :initial => :pending_owner_approval do
event :approve do
transition :from => :pending_owner_approval, :to => :pending_shipping_confirmation
end
event :deny do
transition :from => :pending_owner_approval, :to => :denied
end
# this assumes that it lives in the config directory
set :db_dump_filename, "/tmp/my_app.tar.gz"
namespace :db do
desc 'Copy a remote database to the local development db'
task :copy, :roles => :db, :only => {:primary => true} do
remote_database_yml = capture("cat #{current_path}/config/database.yml")
local_database_yml = File.read(File.dirname(__FILE__) + '/database.yml')
remote_database_config = YAML::load(remote_database_yml)[rails_env]
// Mostly ripped off from here http://santrajan.blogspot.com/2008/10/what-john-resig-did-not-tell-you.html
// Brings a semblance of class hierarchy to jQuery, and allows object to do things, not have things done to them!
var JX = {
extend: function(bc, sc, o) {
var f = function() {};
f.prototype = sc.prototype;
bc.prototype = new f();
bc.prototype.constructor = bc;
bc.superclass = sc.prototype;
=horizontal_scrollbar
&::-webkit-scrollbar
height: 16px
&::-webkit-scrollbar:disabled
height: 0
&::-webkit-scrollbar-button:horizontal
height: 16px
width: 19px
&::-webkit-scrollbar-button:start:decrement:horizontal, &::-webkit-scrollbar-button:end:increment:horizontal
display: block
require 'hpricot'
def formatted_output(node, indent = 0)
output, tag_name = [], node.etag.sub('/', '')
space = ' ' * indent
if node.children
if node.children.size == 1
output << space + node.to_s
else
class Hash
alias_method :old_symbolize_keys, :symbolize_keys
def symbolize_keys
new_hash = old_symbolize_keys
new_hash.each do |k, v|
new_hash[k] = v.symbolize_keys if v.is_a?(Hash)
end
new_hash
end
end
# With a subselect
@authors = Author.find(:all, :conditions => %{id in (
select e.author_id from extensions e where e.size != 0
)})
# With the :joins key
@authors = Author.find(:all, {
:joins => 'extensions on extensions.author_id = authors.id',
:conditions => 'extensions.size != 0',
:readonly => false # Not sure why :joins key implies ":readonly => true"
@siannopollo
siannopollo / cookie.js
Created January 5, 2010 21:34
Cookie library, but splits up large data into separate cookies