Skip to content

Instantly share code, notes, and snippets.

module SymbolizeKeys
# converts any current string keys to symbol keys
def self.extended(hash)
hash.each do |key,value|
if key.is_a?(String)
hash.delete key
hash[key] = value #through overridden []=
end
end
@JoshCheek
JoshCheek / README
Created November 22, 2009 09:33
Testing the differences between references and pointers
*PURPOSE:
This is a test to evaluate the underlying difference between references and pointers.
*PROCESS:
The session can be seen in this image http://grab.by/Jbi
First:
Create a file that uses references (references.cpp), then duplicate it using pointers(pointers.cpp)
# possible solution for ruby-forum.com/topic/203515
$stdin = DATA # uses text after __END__ as input
require 'rubygems' # fixes load path on some (read: most) systems. read ruby-forum.com/topic/203245 to see why it is evil
require 'active_support/inflector' # if you have Rails, you have this library. If not: http://gemcutter.org/gems/activesupport
# the base functionality that you wish to give to the classes that implement the commands
module Command
# possible solution for http://www.ruby-forum.com/topic/145570#887369 by Sergio Bayona
require 'test/unit'
# precondition: to_combine is expected to be in the format given below
# to_combine = [ set1 , set2 , ... , setn ]
# set = { key => values }
# key = any object with hash and eql? methods
# values = [ obj1 , obj2 , ... , objn ]
# obj = any ruby object
# a better h_hat for http://www.gamedev.net/reference/articles/article2003.asp
# better because h_hat <= h, for all 'squares'
require 'test/unit'
ADJACENT_COST = 10
DIAGONAL_COST = 14
def heuristic(y,x)
lesser , greater = [ y.abs , x.abs ].sort
# got inspired to play with files based on this post http://www.ruby-forum.com/topic/206208
# define the constants our MailRecord uses
class MailRecord
LINE_WIDTH = 9 # all lines have this size
LINES_PER_RECORD = 5 # title , id , to , from , blankline
RECORD_WIDTH = LINE_WIDTH * LINES_PER_RECORD
end
# a possible solution for http://www.ruby-forum.com/topic/206291
class Record
# might choose to have it return
def self.group_by_time( records )
records = records.sort_by { |r| r.time }
groups = Array.new
# each consecutive record must be the smallest of the ungrouped records
# an ActiveRecord based solution to http://www.ruby-forum.com/topic/206201
# based on Peter Song's solution
# if anyone is interested in making a DataMapper version of this
# I'd be interested to see how it relates to ActiveRecord :)
require 'rubygems'
require 'hpricot'
require 'open-uri'
# an ActiveRecord based solution to http://www.ruby-forum.com/topic/206201
# based on Peter Song's solution
# showing the use with rails-geocoder for this code http://gist.github.com/338506
# if anyone is interested in making a DataMapper version of this
# I'd be interested to see how it relates to ActiveRecord :)
require 'open-uri'
require 'net/http'
require 'rubygems'
# based on http://gist.github.com/339028
module Base
module Plugins
def plugins
@plugins ||= []
end
def activate plugin
plugins << plugin