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
| # 1) Put this file in your working directory | |
| # 2) run 'sudo gem install active_support grit' | |
| # 3) run 'ruby git-line-count.rb' | |
| # 4) run 'open loc.html' | |
| # 5) yay | |
| require 'rubygems' | |
| require 'active_support' | |
| require 'grit' | |
| require 'open-uri' |
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
| /* Generates a memoizable getter. */ | |
| Object.prototype.memoize = function(key, func) { | |
| var __key__ = "__" + key + "__"; | |
| this.__defineGetter__(key, function() { | |
| if (this[__key__]) return this[__key__]; | |
| this[__key__] = func(); | |
| return this[__key__]; | |
| }); | |
| }; |
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
| ruleset APPID { | |
| meta { | |
| name "Say It (pronunciations)" | |
| description << | |
| You: SMS a word, Me: Call you with a pronunciation | |
| >> | |
| author "Tieg Zaharia" | |
| logging on | |
| key twilio { |
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
| # Overwrites Array#flatten with a new pure Ruby implementation | |
| class Array | |
| def flatten(depth=nil) | |
| ary = [] | |
| self.each do |_| | |
| if _.is_a?(Array) && (depth.nil? || depth > 0) | |
| ary += _.flatten(depth.nil? ? nil : depth - 1) | |
| else | |
| ary << _ | |
| 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 just demonstrates that "Proc.new" will inherit its containing method's proc argument | |
| # if not given an argument. | |
| n = 100_000 | |
| class Foo | |
| def self.return_proc_wout_arg(); Proc.new(); end | |
| end | |
| n.times { (Foo.return_proc_wout_arg {|a| print a }).call('.') } | |
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
| [Thu, 17 Mar 2011 07:39:59 -0700] INFO: Starting Chef Solo Run | |
| /etc/chef-custom/recipes/cookbooks/mysql2/recipes/default.rb:8:in `from_file': undefined method `apps' for #<Mash:0xb77b9924> (NoMethodError) |
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
| # config/initializers/acts_as_list.rb | |
| module ActsAsList::InstanceMethods | |
| private | |
| # change acts_as_list to *only* move a new record to bottom if 'position' value is blank | |
| def add_to_list_bottom_with_check | |
| add_to_list_bottom_without_check if new_record? && self[position_column].blank? | |
| end | |
| alias_method_chain :add_to_list_bottom, :check | |
| 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
| module WillPaginate | |
| class Collection | |
| # This is a special case of paginate() for _dubstep_ fans (_hyper-dubstep_ not supported). | |
| # It is different in this regard: | |
| # * The first page should load +first_per_page+ records | |
| # * The rest of the pages should load +more_per_page+ records | |
| # | |
| # NOTE: will_paginate view helpers not really tested with this (eg the '1,2,3...N' thing) | |
| # | |
| def self.dubstep_paginate(finder, page = 1, first_per_page = 15, more_per_page = 15, finder_opts = {}) |
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
| if /(?<hour>\d?\d)\:(?<min>\d\d)(?<suffix>[pa]m)/ =~ "5:03pm" | |
| puts hour | |
| puts min | |
| puts suffix | |
| 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
| puts a = (2500 * 56) / 10000.0 # => 14.0 | |
| puts b = (250 * 5.6) / 100.0 # => 14.0 | |
| puts c = 25 * 0.56 # => 14.0 | |
| puts a % 1 # => 0 ... Expected | |
| puts b % 1 # => 0 ... Expected | |
| puts c % 1 # => 1.77635683940025e-15 .. Not Expected |