Skip to content

Instantly share code, notes, and snippets.

View batasrki's full-sized avatar

Srdjan Pejic batasrki

  • S-Squared Design & Development
  • Toronto, ON
View GitHub Profile
# Functional test just to demonstrate that everything is hooked up
describe UsersController, "POST create", :type => :controller do
before(:each) do
UsersController.dispatcher = DefaultDispatcher
end
context "successful" do
it "should create a user" do
lambda {
@protocool
protocool / caveatPatchor.js
Created February 11, 2011 01:00
Sample Propane caveatPatchor.js file
/**
Sample Propane caveatPatchor.js file based on tmm1's avatar hack.
You'll need at least version 1.1.1 to experiment with this:
http://propaneapp.com/appcast/Propane.1.1.1.zip
Once I'm sure exposing this hack-injection point doesn't cause problems
I'll do an official auto-updating version.
As of version 1.1.1, Propane will load and execute the contents of

Polymorphism

Sometimes relationships need to be flexible, and that's where we look to polymorphism. Say we want to implement:

  • A Person
  • A Company
  • A PhoneNumber that can connect to a Person or a Company

At the Database Level

@dkubb
dkubb / .rvmrc
Created August 10, 2011 22:44
Web framework Spike
rvm use @$(basename `pwd`) --create
@avdi
avdi / when.rb
Created December 5, 2011 22:17
Experimenting with Object#when in Ruby
def maybe_a_sandwich
nil
end
# Methods that might return nil are annoying. We want to write a nice
# confident chain:
result = nil
result = maybe_a_sandwich.add_horseradish.get_into_my_belly! rescue $!
result # => #<NoMethodError: undefined method `add_horseradish' for nil:NilClass>
@ryanb
ryanb / index.js.erb
Created December 16, 2011 23:22
Infinite scrolling solution covered in revised episode #114: http://railscasts.com/episodes/114-endless-page-revised
$('#products').append('<%= j render(@products) %>');
<% if @products.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@products) %>');
<% else %>
$('.pagination').remove();
<% end %>
def output name=((default=true); "caius")
puts "name: #{name.inspect}"
puts "default: #{default.inspect}"
end
output
# >> name: "caius"
# >> default: true
output "avdi"
SiloRackApp = Rack::Builder.new do
use Rack::Runtime # add X-Runtime header
use E20::Ops::Middleware::RevisionMiddleware, logger: Silo.logger
use E20::Ops::Middleware::TransactionIdMiddleware, logger: Silo.logger
use E20::Ops::Middleware::HostnameMiddleware, logger: Silo.logger
use Clogger,
format: Clogger::Format::Combined,
path: File.join(Silo::ROOT, 'log', 'silo.access.log'),
reentrant: true
@justinko
justinko / gist:1684051
Created January 26, 2012 17:59
Methods to aid in testing without loading the Rails environment
def stub_model(model_name)
stub_class model_name, ActiveRecord::Base
end
def stub_class(class_name, super_class = Object)
stub_module class_name, Class.new(super_class)
end
def stub_module(module_name, object = Module.new)
module_name = module_name.to_s.camelize
@burke
burke / 0-readme.md
Created January 27, 2012 13:44 — forked from funny-falcon/cumulative_performance.patch
ruby-1.9.3-p327 cumulative performance patch for rbenv

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.