Skip to content

Instantly share code, notes, and snippets.

View saturnflyer's full-sized avatar
😀

Jim Gay saturnflyer

😀
View GitHub Profile
@saturnflyer
saturnflyer / topics.md
Last active December 22, 2015 19:59
newsletter topics
  1. Ruby Delegate.rb Secrets
  2. Simple presenters to clean up views
  3. Ruby Forwardable in Depth
  4. how it works
  5. SingleForwardable
  6. identifying responsibility leaks with if
  7. enforcing encapsulation
  8. seeing the westward flow and heading east
  9. ActiveSupport::Delegation, the Rails approach to forwarding
  10. The Casting gem and why it's different from SimpleDelegator
@saturnflyer
saturnflyer / gol.rb
Last active December 21, 2015 00:09
Conway's Game of Life
seed = [[0,0],[0,1],[0,2]]
puts "First generation:"
puts seed.to_s
# Point surrounding a given point
perimeter = ->(x, y){
[
[x - 1, y + 1], [x, y + 1], [x + 1, y + 1],
[x - 1, y ], [x + 1, y ],
[x - 1, y - 1], [x, y - 1], [x + 1, y - 1]
@saturnflyer
saturnflyer / multiwrapper.rb
Last active December 20, 2015 13:48
Maybe get values from an object. Wrap one object, but check if an alternate one has better data first. In this case, we wrap a user object, but for the methods we specify we can check the profile object for data before falling back to the user.
require 'delegate'
class SpecialFormatter < SimpleDelegator
def initialize(user, profile)
super(user)
@profile = profile
end
attr_reader :profile
def self.maybe(*names)
@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
@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"