Skip to content

Instantly share code, notes, and snippets.


Renato Zannon renato-zannon

View GitHub Profile
renato-zannon / results
Created Jun 5, 2014
Rust: Semaphores vs channels
View results
running 2 tests
test with_channels ... bench: 876410 ns/iter (+/- 655463)
test with_semaphores ... bench: 513476 ns/iter (+/- 711503)
test result: ok. 0 passed; 0 failed; 0 ignored; 2 measured

Keybase proof

I hereby claim:

  • I am renato-zannon on github.
  • I am renato_zannon ( on keybase.
  • I have a public key whose fingerprint is 723E BFA3 0EBE 26C6 4310 5364 6C26 8AF6 75E7 D62E

To claim this, I am signing this object:

renato-zannon / named_dynamic_methods.rb
Created Sep 20, 2011
A simple practice to help your fellow workers navigate your dynamic ruby code
View named_dynamic_methods.rb
# It's common, while creating a bunch of very similar methods, to create
# a loop to define them all at once. (Very simple) example follows:
week_days = %w[sunday monday tuesday wednesday thursday friday saturday]
week_days.each do |day|
define_method("events_on_#{day}") do { |event| == day }
renato-zannon / gist:1290010
Created Oct 15, 2011
Inject alternate implementation
View gist:1290010
module Inject
class Injector
def self.inject(*args, &block)
options = args.last.kind_of?(Hash) ? args.pop : {}
target = options[:receiver] || block.binding.eval("self")
modules = args
modules.each { |mod| mod.before_inject(target) if mod.respond_to?(:before_inject)}
return_value = new(modules).inject_into(target, &block)
View gist:1311185
import Control.Monad
data Tree a = EmptyTree | Node a (Tree a) (Tree a)
(<<) EmptyTree value = Node value EmptyTree EmptyTree
(<<) (Node value left right) newValue = if newValue < value
then Node value (left << newValue) right
else Node value left (right << newValue)
toArray EmptyTree = []
renato-zannon / xmonad-unity.desktop
Created Jan 13, 2012
Unity Panel + XMonad config
View xmonad-unity.desktop
# /usr/share/xsessions/xmonad-unity.desktop
[Desktop Entry]
Exec=gnome-session --session=xmonad_unity
renato-zannon / user.rb
Created Jun 9, 2012
Strategy pattern to follow users
View user.rb
class User <, :private)
alias_method :private?, :private
def follow
def follow_strategy
View fiber-example.rb
# Depends on gems eventmachine, em-http-request,
# and em-resolv-replace (for # async DNS)
require 'eventmachine'
require 'em-http'
require 'fiber'
require 'em-resolv-replace'
def make_request_to(url)
connection =
View nth_child.rb
require 'nokogiri'
require 'rspec'
describe "nth-child" do
let(:doc) do
<p id="first"></p>
<p id="second"></p>
renato-zannon / module.rb
Created Sep 4, 2012
Subclass module + use module_eval to define methods
View module.rb
class AttributeAccessor < Module
def initialize(name)
@name = name
module_eval { define_accessors }
def define_accessors
ivar = "@#{@name}"