Skip to content

Instantly share code, notes, and snippets.

View eregon's full-sized avatar

Benoit Daloze eregon

View GitHub Profile
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
@jwhitmire
jwhitmire / Ode to _why
Created August 20, 2010 02:50
Happy _whyday everybody! In honor of his absence, I've composed a little haiku that I think _why would appreciate. I think you'll agree it's quite ... like the man himself.
_why the lucky stiff
his brain was rare in the world
hackety hack -- brilliant
_why the lucky stiff
we miss him even today
how very poignant
_why the lucky stiff
sometimes didn't make much sense
@mnutt
mnutt / Instrument Anything in Rails 3.md
Created September 6, 2010 06:50
How to use Rails 3.0's new notification system to inject custom log events

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)

@juliocesar
juliocesar / testing_front_end_rspec_capybara.md
Created October 21, 2010 23:51
Testing front-end for a Sinatra app with RSpec and Capybara

Testing front-end for a Sinatra app with RSpec and Capybara

I've used Cucumber quite a bit on my last job. It's an excellent tool, and I believe readable tests are the way to the future. But I could never get around to write effective scenarios, or maintain the boatload of text that the suite becomes once you get to a point where you have decent coverage. On top of that, it didn't seem to take much for the suite to become really slow as tests were added.

A while ago I've seen a gist by Lachie Cox where he shows how to use RSpec and Capybara to do front-end tests. That sounded perfect for me. I love RSpec, I can write my own matchers when I need them with little code, and it reads damn nicely.

So for my Rails Rumble 2010 project, as usual, I rolled a Sinatra app and figured I should give the idea a shot. Below are my findings.

Gemfile

#!/usr/bin/env ruby
=begin
INSTALL:
curl http://github.com/defunkt/gist/raw/master/gist.rb > gist &&
chmod 755 gist &&
sudo mv gist /usr/local/bin/gist
@igrigorik
igrigorik / webapp.rb
Created November 13, 2010 21:28
Inspired by @JEG2's talk at Rubyconf... Any ruby object, as a webapp! 'Cause we can. :-)
require 'rubygems'
require 'rack'
class Object
def webapp
class << self
define_method :call do |env|
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, send(func, *attrs)]
end
@ged
ged / parasite.rb
Created November 13, 2010 23:33
More cool/stupid Method#to_proc tricks
#!/usr/bin/env ruby -wKU
### A parasitic class
class Parasite
### Make all future instances of the Parasite actually call
### methods of the +victim+ instead.
def self.infest( victim )
victim.methods.each do |m|
meth = victim.method( m )
require "rubygems"
require "sinatra"
get "/next" do
tell_itunes "next track"
end
get "/previous" do
tell_itunes "previous track"
end
@funny-falcon
funny-falcon / patch-1.9.2-gc.patch
Created March 5, 2011 11:11
GC tunning simple patch ruby 1.9.2 p180
diff --git a/gc.c b/gc.c
--- a/gc.c
+++ b/gc.c
@@ -77,6 +77,41 @@ void *alloca ();
#ifndef GC_MALLOC_LIMIT
#define GC_MALLOC_LIMIT 8000000
#endif
+#define HEAP_MIN_SLOTS 10000
+#define FREE_MIN 4096
+