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
This example shows how to setup an environment running Rails 3 beta under 1.9.1 with a 'rails3' gem set. | |
((This is a fork of wayne, please see his gist if you want recent syntax for rvm. | |
Mainly, gems is replaced by gemset)) | |
∴ rvm update --head | |
# ((Open a new shell)) | |
# If you do not already have the ruby interpreter installed, install it: | |
∴ rvm install 1.9.1 |
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
# Implement 'go to higher neighbour' algorithm | |
class Coord < Struct.new(:x, :y) | |
@@coords = [] | |
def to_s | |
"#{x} #{y}" | |
end | |
alias :inspect :to_s | |
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
# Ruby Quiz #234 : Random Points within a Circle | |
# Benoit Daloze | |
include Math | |
class Point < Struct.new(:x, :y) | |
def distance to | |
hypot(x-to.x, y-to.y) | |
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
Ceci est un essai de réponse en Ruby à: | |
http://lasts.goldzoneweb.info/pf.html |
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
require "benchmark" | |
require "thread" | |
require "thread/queue" | |
methods = { | |
push: -> q { N.times { |i| q.push i } }, | |
pop: -> q { N.times { |i| q.pop } }, | |
empty?: -> q { | |
(N/2).times { |i| q.empty? } | |
q.push :tmp |
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
--trace ruby -v | |
rvm 0.1.45 by Wayne E. Seguin (wayneeseguin@gmail.com) [http://rvm.beginrescueend.com/] | |
+__rvm_parse_args:434> [[ -z '' ]] | |
+__rvm_parse_args:434> [[ ! -z ruby-1.9.2-rc2 ]] | |
+__rvm_parse_args:434> rvm_action=use | |
+__rvm_parse_args:435> [[ ! -z '' ]] | |
+__rvm_parse_args:435> [[ ! -z '' ]] | |
+__rvm_parse_args:9> [[ 2 -gt 0 ]] |
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
[32minfo[m: default (ruby-head@global): ruby 1.9.3dev (2010-08-13) [x86_64-darwin10.4.0] | |
ruby 1.9.3dev (2010-08-13) [x86_64-darwin10.4.0] | |
[32minfo[m: ruby-1.8.7-head (ruby-1.8.7-head@global): ruby 1.8.7 (2010-07-17 patchlevel 300) [i686-darwin10.4.0] | |
ruby 1.8.7 (2010-07-17 patchlevel 300) [i686-darwin10.4.0] | |
[32minfo[m: ruby-1.8.7-head@global: ruby 1.8.7 (2010-07-17 patchlevel 300) [i686-darwin10.4.0] |
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
# Binding.of_caller | |
# Revisited for 1.9 | |
# eregon | |
=begin | |
def Binding.of_caller(&block) | |
old_critical = Thread.critical | |
Thread.critical = true | |
count = 0 | |
cc, result, error = Continuation.create(nil, nil) |
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
# encoding: utf-8 | |
require "io/console" | |
def ⌛() STDIN.getch end | |
alias λ lambda | |
alias ✎ puts | |
def ❄() λ { |e| ✎ e } end | |
Fiber.new { |b = -> w { ✎ w }| | |
loop do | |
b[Fiber.yield] |
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
require 'benchmark' | |
N = 10000 | |
HASH_SIZE = 10 | |
HASH = {} | |
HASH_SIZE.times do |n| | |
HASH[n] = (rand * 100).round - 50 | |
end | |
puts HASH.inspect |
OlderNewer