This file contains hidden or 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 ActionController::Integration::Session | |
# Intercepts a request to a foreign domain. Use this to stub | |
# a service which the user is bounced through, such as an | |
# OpenID provider. The block should return a new URL to | |
# request. This is the URL which the foreign service would | |
# redirect the browser to if we were really using it. | |
# | |
# Currently, the return URL can only be requested with a GET. | |
# | |
# stub_request 'foreign.host.com' do |path| |
This file contains hidden or 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
# From http://wonderfullyflawed.com/2008/05/21/clearfix-as-mixin/ | |
=clearfix | |
*display: inline-block | |
&:after | |
content: " " | |
display: block | |
height: 0 | |
clear: both | |
visibility: hidden |
This file contains hidden or 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
# How does that session value get set!? | |
require 'metaid' | |
@response.session.metaclass.class_eval do | |
def []=(k,v) | |
puts "Setting session[#{k.inspect}] = #{v.inspect} (#{caller[0]})" | |
super | |
end | |
end |
This file contains hidden or 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 'osx/cocoa' | |
include OSX | |
things_path = NSWorkspace.sharedWorkspace.fullPathForApplication("Things") | |
things_bundle = NSBundle.bundleWithPath(things_path) | |
NSManagedObjectModel.mergedModelFromBundles([things_bundle]).entities.each { |e| puts e.name } | |
# >> Record | |
# >> SyncedTask | |
# >> MobileSyncItem | |
# >> Focus |
This file contains hidden or 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 User < ActiveRecord::Base | |
# This is begging to be a plugin, or even a gem. | |
def self.new(*_) | |
raise "Code is an abstract class and cannot be instantiated" if self == User | |
super | |
end | |
# ... | |
end |
This file contains hidden or 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 'activesupport' | |
# Let's say there's some Widget class. | |
class Widget | |
def sproing | |
[:original] | |
end | |
end |
This file contains hidden or 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
@importer....should contain.blahblahs.that { should include("foo") and should_not include("bar") } |
This file contains hidden or 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
named_scope :valid_for_state_and_user, lambda { |state, user| lambda { |transition| | |
transition.from_state_id == state.id && | |
!transition.protected? or user.role.can_apply_protected_note_transitions? | |
}} |
This file contains hidden or 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
# Dan Chak, author of O'Reilly's "Enterprise Rails" thinks that Ruby has inner methods. | |
# See "Enterprise Rails", pg. 140. | |
class Foo | |
def bar | |
"outer bar" | |
end | |
def foo | |
# Dan Chak thinks this can only be called from within #foo. |
This file contains hidden or 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
module Curryable | |
# Quirk: #curry on a nullary function calls the function. | |
def curry(args = []) | |
if self.arity == args.length | |
self[*args] | |
else | |
lambda do |next_arg| | |
self.curry(args + [next_arg]) | |
end | |
end |