Skip to content

Instantly share code, notes, and snippets.

View IndianGuru's full-sized avatar

IndianGuru IndianGuru

View GitHub Profile
class String
alias_method :is_a, :==
alias_method :is_an, :==
end
class Maze
NAVIGABLE = ' '
WALL = '#'
POINT_A = 'A'
@IndianGuru
IndianGuru / maze.rb
Created January 14, 2010 05:06 — forked from anonymous/maze.rb
class Maze
attr_reader :maze_array
def initialize(maze)
@maze_array = maze.split("\n") #create array of lines of the string
@maze_array.map! { |line| line.chars.to_a } #converts array to 2-d array of characters in maze
raise ArgumentError, "All lines must be of the same length", caller if !@maze_array.all? {|line| line.length == @maze_array[0].length}
@height = @maze_array.length #store the height of the maze in an instance variable
@width = @maze_array[0].length #store the length of the maze in an instance variable (assumes each line is the same length - should really test for this if being thorough)
@maze_array.each_with_index do |line, index1| #search array to find start and end of maze
line.each_with_index do |char, index2|
class Maze
Cardinals = Proc.new{|(x,y)| [[x-1,y],[x,y+1],[x+1,y],[x,y-1]].select{|c| c.min >= 0}}
MazeSeperator, MazeStart, MazeWall, MazeEnd, MazeOOB = "\n", 'A', '#', 'B', nil
Infinity = 1.0/0
X, Y = 0, 1
def initialize(maze)
raise ArgumentError, 'No end point' unless maze.include? MazeEnd
raise ArgumentError, 'No start point' unless maze.include? MazeStart
@IndianGuru
IndianGuru / maze.rb
Created January 18, 2010 12:33 — forked from patio11/maze.rb
#This solves the maze using regular expressions, because I am too
#lazy to worry about arrays, darn it. It is inefficient as heck and designed
#purely to demonstrate perversion of sound CS principals.
#
# Code by Patrick McKenzie, 2010. I release this work unto the public domain.
class Maze
def initialize(maze_string)
@width = maze_string.split("\n")[0].length #width of maze in characters
@guts = maze_string.gsub("\n", "") #maze as a flat string -- no newlines
require 'test/unit'
require 'fair_distribution'
#FairDistribution = LowMemoryFairDistribution
class FairQueueTest < Test::Unit::TestCase
def test_basic1
jobs = [10, 15, 20, 24, 30, 45, 75]
number_of_presses = 2
8th Feb 2010
Hello,
I have been associated with Ruby since 2005 and run the RubyLearning group of sites ( http://rubylearning.org/ | http://rubylearning.com/ | http://rubylearning.com/blog/ ) and the PuneRuby User Group ( http://tech.groups.yahoo.com/group/puneruby/ ) .
I am writing a blog post titled "Indian Ruby on Rails Portfolio" which would go live on Tuesday 23rd Feb. 2010. This blog post would showcase Indian websites made with Ruby on Rails. A post on the RubyLearning blog is immediately picked up by RubyInside and RubyFlow readers and Rails news aggregators around the world and so the listed sites would get good mileage.
If you are the owner / developer of such a website(s), then I would appreciate if you would send me by email, as much information about the same. Namely, a -
a. 150×91 thumbnail and the URL to the website.
@IndianGuru
IndianGuru / rlrubyists.txt
Created February 21, 2010 07:52
RubyLearning's Awesome Rubyists
We have some amazing, talented Rubyists who have been associated with RubyLearning these past 4 years. I plan to write a blog post titled "Showcasing RubyLearning's Awesome Rubyists" (you can suggest me a different title too). Who are these awesome Rubyists? YOU. Yes, if you are working / or are a hobbyist in Ruby or Sinatra or Rails then I would like to feature you on my RubyLearning blog at http://rubylearning.com/blog/ A post on the RubyLearning blog is immediately picked up by RubyInside and RubyFlow readers and Rails news aggregators around the world and so you can get maximum coverage!
If I receive inputs from at least 10 of you, I shall write this blog post.
Please send me the following information at satish.talim@gmail.com -
a. Your full name
b. The country where you stay currently
c. Your email id
d. Educational qualifications
@IndianGuru
IndianGuru / OtherRubyConf
Created February 7, 2011 11:51
Other Ruby Rails conf tentative/scheduled dates in May/June 2011
05/05 - 05/06 (Thu-Fri): Frozen Rails (Helsinki, Finland) [TENTATIVE]
05/16 - 0519 (Mon-Thu): RailsConf (Baltimore, MD) [CONFIRMED]
05/28 - 05/29 (Sat-Sun): Euruko (Berlin, GER) [CONFIRMED]
06/04 - 06/05 (Sat-Sun): Great Lakes Ruby Bash (Cleveland, OH) [TENTATIVE]
06/10 - 06/13 (Fri-Mon): Rails Camp 9 Australia (Lennox Head, NSW) [CONFIRMED]
@IndianGuru
IndianGuru / sample1.rb
Created August 26, 2011 03:58
Sample 1
def factorial(n)
(1..n).inject(1) { |product, value| product * value }
end
@IndianGuru
IndianGuru / jruby01.rb
Created August 28, 2011 00:56
JRuby programs
# First get the current local time
t = Time.now
# to get day, month and year with century
# also hour, minute and second
puts t.strftime("%d/%m/%Y %H:%M:%S")
# You can use the upper case A and B to get the full
# name of the weekday and month, respectively
puts t.strftime("%A")
puts t.strftime("%B")