Skip to content

Instantly share code, notes, and snippets.

View saturnflyer's full-sized avatar
😀

Jim Gay saturnflyer

😀
View GitHub Profile
MarkdownFilterExtension.setup do |config|
config.auto_ids = false
config.parse_block_html = false
end
Bump:~ jim$ curl https://github.com/atmos/cinderella/raw/master/bootstrap.sh -o - | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
102 1333 102 1333 0 0 5016 0 --:--:-- --:--:-- --:--:-- 31738
Ensuring we have the latest version of cinderella installed
A first time install takes about 45 minutes on a modern machine
Cinderella installed successfully
[Thu, 02 Dec 2010 23:42:05 -0500] INFO: Setting the run_list to ["homebrew", "homebrew::dbs", "homebrew::misc", "ruby", "ruby::irbrc", "node", "python"] from JSON
[Thu, 02 Dec 2010 23:42:05 -0500] INFO: Starting Chef Run (Version 0.9.12)
[Thu, 02 Dec 2010 23:42:05 -0500] ERROR: Running exception handlers
@saturnflyer
saturnflyer / gist:943663
Created April 27, 2011 03:25
Method fallback
# Instead of writing ternary operators with respond_to?:
# obj.respond_to?(:method_one) ? obj.method_one : obj.method_two
# I want something simpler
class Object
def fallback(*args)
method_to_try = args.find{|meth| self.respond_to?(meth) && meth.to_s != __method__.to_s }
self.send(method_to_try)
end
alias trial fallback
alias trip fallback
@saturnflyer
saturnflyer / permit.rb
Created June 7, 2011 00:50
Simple permissions
# A small example of Method Forwarding
#
# The permissions are stored on the object concerned with access control.
# You send a message to one object, which forwards it to the access controller.
class User
attr_accessor :zombie
def method_missing(meth, object, *args)
if object.permissions
object.send(meth, self, *args)
@saturnflyer
saturnflyer / gist:1149452
Created August 16, 2011 16:14
Testing named routes in Rails 3
require 'test_helper'
class RoutesTest < ActionController::TestCase
include Rails.application.routes.url_helpers
# standard Rails stuff without testing the named helpers
test 'should route the unusual path to the something custom action' do
assert_routing({ :method => 'get', :path => '/unusual/path' }, { :controller => "something", :action => "custom" })
end
@saturnflyer
saturnflyer / gist:1351998
Created November 9, 2011 16:37
simple load path handling
def needs(short_path)
full_path = File.expand_path(__FILE__ + '../../../' + short_path)
unless $:.include?(full_path)
$: << full_path
end
end
# Example use:
# needs('app/models')
# require 'my_model'
@saturnflyer
saturnflyer / gist:1515021
Created December 23, 2011 18:32
allowing objects to specify exception types
class Share
def call
list.each do |address|
begin
referral = new_referral(address)
referral.save
rescue referral.invalid_exception_type
@unsaved << referral
end
end
@saturnflyer
saturnflyer / gist:1540782
Created December 30, 2011 17:50
Upgrading from Radiant 0.9.1 to a 1.0 version
project_type = :rails
project_path = Compass::AppIntegration::Rails.root
http_path = "/"
http_stylesheets_path = "/stylesheets"
http_images_path = "/images"
http_javascripts_path = "/javascripts"
sass_dir = "public/stylesheets/sass"
css_dir = "tmp/public/stylesheets"
project_type = :rails
project_path = Compass::AppIntegration::Rails.root
http_path = "/"
http_stylesheets_path = "/stylesheets"
http_images_path = "/images"
http_javascripts_path = "/javascripts"
sass_dir = "public/stylesheets/sass"
css_dir = "tmp/public/stylesheets"