Skip to content

Instantly share code, notes, and snippets.

View eregon's full-sized avatar

Benoit Daloze eregon

View GitHub Profile
@eregon
eregon / gist:310469
Created February 21, 2010 19:07 — forked from wayneeseguin/gist:296055
Rails 3 rvm gemsets
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
# Implement 'go to higher neighbour' algorithm
class Coord < Struct.new(:x, :y)
@@coords = []
def to_s
"#{x} #{y}"
end
alias :inspect :to_s
# 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
Ceci est un essai de réponse en Ruby à:
http://lasts.goldzoneweb.info/pf.html
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
--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 ]]
info: 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]
info: 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]
info: ruby-1.8.7-head@global: ruby 1.8.7 (2010-07-17 patchlevel 300) [i686-darwin10.4.0]
# 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)
# 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]
require 'benchmark'
N = 10000
HASH_SIZE = 10
HASH = {}
HASH_SIZE.times do |n|
HASH[n] = (rand * 100).round - 50
end
puts HASH.inspect