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
| # hoptoad webistrano recipe | |
| # works with Rails 3 | |
| after "deploy", "deploy:notify_hoptoad" | |
| after "deploy:migrations", "deploy:notify_hoptoad" | |
| namespace :deploy do | |
| desc "Notify Hoptoad of the deployment" | |
| task :notify_hoptoad do | |
| rails_env = fetch(:hoptoad_env, fetch(:rails_env, "production")) |
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
| # Copyright 2010, Iain Hecker. All Rights Reserved | |
| # Conway's Game of Life, in one line of Ruby. | |
| # http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life | |
| # Tested and found working on Ruby 1.8.7 and 1.9.2 | |
| # The grid is spherical or "wrap around", so the left is connected to the right and top to bottom. | |
| # | |
| # Generate a random grid, 30 cells wide and 10 cells high | |
| # | |
| # grid = "30x10".to_grid | |
| # |
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
| # IRBRC file by Iain Hecker, http://iain.nl | |
| # put all this in your ~/.irbrc | |
| require 'rubygems' | |
| require 'yaml' | |
| alias q exit | |
| class Object | |
| def local_methods | |
| (methods - Object.instance_methods).sort |
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 Post | |
| def initialize(attributes = {}) | |
| @attributes = attributes | |
| end | |
| def publishable? | |
| @attributes[:approved] | |
| 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
| # Writing Genesis in Ruby, for http://www.whatdigitalrevolution.com/?p=119 | |
| God = "God" | |
| def God.performs &acts | |
| instance_eval &acts | |
| end | |
| def God.create *stuff | |
| "#{self} created #{stuff.join(' and ')}." |
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
| # Without Symbol#to_proc | |
| [1, 2, 3].map { |it| it.to_s } | |
| [3, 4, 5].inject { |memo, it| memo * it } | |
| # With Symbol#to_proc | |
| [1, 2, 3].map(&:to_s) | |
| [3, 4, 5].inject(&:*) |
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
| var MyClass = new Function(); | |
| MyClass.prototype = { | |
| /** | |
| * bind(Function) -> Function | |
| * | |
| * The problem with jQuery is that jQuery methods change +this+ inside their | |
| * callbacks. This looses your reference to the current object. Pass the | |
| * callback-function to +bind+ and it fixes it for you. | |
| * |
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 File.join(File.dirname(__FILE__), 'config', 'environment') | |
| require 'ya2yaml' | |
| module PrettyYaml | |
| class << self | |
| def write(filename, hash) | |
| File.open(filename, "w") do |f| | |
| f.write(yaml(hash)) | |
| 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
| # This a sample YML file from Rails 2.3. The objective is to propose a yml based on this | |
| # one which will reduce error messsages duplication, as outline in this post: | |
| # | |
| # http://groups.google.com/group/rails-i18n/browse_thread/thread/3085a78831ed8fae | |
| # | |
| # Proposals are available below and also check the forks at the right. | |
| en: | |
| activerecord: | |
| models: | |
| admin: "Admin" |
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 ActiveRecord::Base | |
| named_scope :all, lambda { |*options| options.first || {} } | |
| end |