Skip to content

Instantly share code, notes, and snippets.

View saturnflyer's full-sized avatar
😀

Jim Gay saturnflyer

😀
View GitHub Profile
@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"
@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
@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 / 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: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 / dynamic_initialize.rb
Created July 10, 2013 14:11
Dynamically defining the initialize method and setting the arity.
class Something
def self.init(*init_args)
# this works but...
define_method(:initialize){|*args|
# arity is -1
}
class_eval %Q<
def initialize(#{*init_args})
@saturnflyer
saturnflyer / gist:6011386
Last active December 19, 2015 20:09
mail helper
def custom_mail_to(email, link_text, i18n_subject_key)
mail_to(email, link_text, :subject => I18n.t(i18n_subject_key, :email => email))
end