Skip to content

Instantly share code, notes, and snippets.

# API Showcase
svg = Ralphy::Container.new(width:300,height:200)
# Drawing a simple circle within a rectangle:
# All of Ralphy's classes derive from Nokogiri's
circle = Ralphy::Circle.new # Can't be added to svg until all its required arguments are passed (center and radius)
# maze.rb, by Othmane Benkirane.
# only tested with ruby 1.9.1p376 (2009-12-07 revision 26041).
# will definitely not work with ruby 1.8.
=begin
Algorithm for steps:
- @steps is populated with the starting cell in the beginnign ('A')
- Until a solution is found, @steps replaces its content by the
possible next steps
- If a solution is found, the number is returned, if a solution isn't found
(if @steps is empty), an error is raised (the loop is broken) and rescued
>> require 'mongo_mapper'
=> true
>> MongoMapper.database = 'itsatest'
=> "itsatest"
>> class Person
>> include MongoMapper::Document
>> key :first_key
>> end
=> #<MongoMapper::Key:0x101fe92a8 @name="first_key", @type=nil, @default_value=nil, @options={}>
>> first = Person.new(:first_key => 'first_value')
def files(first_path, glob_path, &block)
# With this block, there is no problem.
# block = :to_s.to_proc
iteration = proc do |num, path|
tmppath = "#{Dir.tmpdir}/#{path}"
::FileUtils.mkdir_p(::File.dirname(tmppath))
::File.open(tmppath, 'w+') {|f| f.puts(block.call(num))}
Battuta::File(tmppath).path = path
end
iteration[0, first_path]
#!/usr/bin/env ruby
# Polynomial beautifier, by Othmane Benkirane
# The code passes the test but why is @p4 considered as a polynomial ?
# An ArgumentError should be thrown.
# Oh, and... it's got a lot of unseen features. Just see my personal
# specs. It's possible to have a beautiful output (2x³+3x²+10x-1)
# and also several compression types: (x + 5) or (2x² -3x +5)
# Also, shouldn't we do that: puts @polynomial.to_s
$am_pm = false
def average_time_of_day(times)
Time.at(
times.map! { |t| if t =~ /(\d+):(\d+)(\w*)/
military = ($1+$2).to_i
[if (1200..1259) === military && $3 == 'am'; 0
elsif (100..1159) === military && $3 == 'pm'; $1.to_i+12
else; $1.to_i
end, $2.to_i]
end}.map!.with_index {|t,i| t[0] += 24 if t[0] < times[i-1][0] && i!=0; t}.
def average_time_of_day(times)
times.map! {|time| time.scan(/(\d+):(\d{2})(\w{2})/)}.
map! {|l| l[0].first(2).map(&:to_i) << (l[0].last == 'pm')}
seconds = 0
times.each { |t| seconds += t[0]*3600 + (12 if t[2]).to_i + t[1]*60 }
average = seconds/times.size
hours = average/3600
hours, minutes, ampm = hours-(12 if hours>12).to_i, (average- hours*3600)/60,
hours>12 ? 'pm' : 'am'
"#{hours}:#{minutes}#{ampm}"
#!/usr/bin/env ruby
%w[rubygems sinatra jsmin cssmin].each{|l| require l}
configure do
set :bundle, 'bundle'
end
configure :development do
set :js_proc, proc {|f| "\n/* '#{f}' */\n" + File.read(f)}
set :css_proc, proc {|f| "\n/* '#{f}' */\n" +File.read(f)}
hy@eo:/tmp/redcar$ rake build
(in /tmp/redcar)
cd /tmp/redcar
Libraries
glib-2.0...................... found
gtksourceview-2.0............. found
Oniguruma..................... found
Libgee........................ found
ruby-dbus..................... found
http://siriis.files.wordpress.com/2008/08/dessin_peyton_161.jpg
http://www.cohesionsociale.gouv.fr/
http://fr.wikipedia.org/wiki/Cohésion_sociale