Skip to content

Instantly share code, notes, and snippets.

View saturnflyer's full-sized avatar
😀

Jim Gay saturnflyer

😀
View GitHub Profile
@saturnflyer
saturnflyer / gist:5788041
Last active December 18, 2015 13:09
This is a class methods that allows you to simplify the setup of arguments, objects, and methods.
class Something
setup(:first, :second)
module Second
end
end
# This is the equivalent of what the code above does...
class Something
@saturnflyer
saturnflyer / gist:5403871
Created April 17, 2013 12:32
What I want to do with representable
class Mapper
with_options :prefix => 'special_' do
property :id
property :name
property :other
end
end
# This would yield {"special_id" => 1, "special_name" => 'something', "special_other" => 'other value' }
@saturnflyer
saturnflyer / gist:4446619
Created January 3, 2013 20:03
brew install -v graphviz
brew install -v graphviz
==> Downloading http://www.graphviz.org/pub/graphviz/stable/SOURCES/graphviz-2.28.0.tar.gz
Already downloaded: /Library/Caches/Homebrew/graphviz-2.28.0.tar.gz
/usr/bin/tar xf /Library/Caches/Homebrew/graphviz-2.28.0.tar.gz
==> Downloading patches
/usr/bin/curl -f#LA Homebrew 0.9.3 (Ruby 1.8.7-358; Mac OS X 10.8.2) https://trac.macports.org/export/78507/trunk/dports/graphics/graphviz-gui/files/patch-project.pbxproj.diff -o 001-homebrew.diff
######################################################################## 100.0%
==> Patching
/usr/bin/patch -f -p1 -i 000-homebrew.diff
patching file lib/gvc/Makefile.in
@saturnflyer
saturnflyer / Alternate.rb
Created August 28, 2012 16:46
Radiant custom tag ideas
# This is from a production application of mine
def ExpertTag(tag)
tag.is_a?(ExpertTag) ? tag : ExpertTag.new(tag)
end
class ExpertTag
def initialize(radius_tag)
@radius_tag = radius_tag
end
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"
@saturnflyer
saturnflyer / gist:1540782
Created December 30, 2011 17:50
Upgrading from Radiant 0.9.1 to a 1.0 version
@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: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: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