This file contains 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 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 |
This file contains 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
*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) |
This file contains 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
# 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 |
This file contains 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
# 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 |
This file contains 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
# 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 |
This file contains 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
# 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 | |
This file contains 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
# 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 |
This file contains 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
# 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' |
This file contains 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
# 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' |
This file contains 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
# based on http://gist.github.com/339028 | |
module Base | |
module Plugins | |
def plugins | |
@plugins ||= [] | |
end | |
def activate plugin | |
plugins << plugin |
OlderNewer