Skip to content

Instantly share code, notes, and snippets.

View dcadenas's full-sized avatar

Daniel Cadenas dcadenas

View GitHub Profile
require 'rubygems'
require 'preforker'
require 'eventmachine'
class EchoServer < EM::Connection
def notify_readable
while socket = @io.accept_nonblock
message = socket.gets
socket.write message
socket.close
@dcadenas
dcadenas / cdgem
Created September 14, 2010 19:29
# cd into matching gem directory ("cd -" friendly)
cdgem() {
local gempath=$(gem env gemdir)/gems
if [[ $1 == "" ]]; then
cd $gempath
return
fi
local gem=$(ls $gempath | g $1 | sort | tail -1)
if [[ $gem != "" ]]; then
class Object
def send(*args, &block)
"no soy sarasa porque me piso el send"
end
def sarasa
"soy sarasa"
end
end
#!/usr/bin/env ruby
require 'benchmark'
Benchmark.bm do|b|
b.report("block") do
(1..1000000).map {|n| Math.log(n) }
end
b.report("to_proc") do
(1..1000000).map &Math.method(:log)
require 'state_pattern'
class Stop < StatePattern::State
def next
sleep 3
transition_to(Go)
end
def color
"Red"
@dcadenas
dcadenas / desugared-coffeescript.coffee
Created September 7, 2011 05:31
Desugared Coffeescript class definitions
#sugared
do ->
class Animal
constructor: (@name) ->
move: (meters) ->
alert @name + " moved #{meters}m."
class Snake extends Animal
move: ->
@dcadenas
dcadenas / gist:1395643
Created November 26, 2011 13:11 — forked from nu7hatch/gist:1395642
Preguntas webrocket
Quien es tu cliente?
Desarrolladores
Cual es tu propuesta de valor?
Facilitar la comunicación browser-servidor en tiempo real
Cuales son tus fuentes de ingresos?
Cual es tu estructura de costos?
@dcadenas
dcadenas / gist:1395726
Created November 26, 2011 13:59 — forked from elcuervo/gist:1395652
Preguntas webrocket
Quien es tu cliente?
Desarrolladores/Web shops
Cual es tu propuesta de valor?
Facilitar la comunicación browser-servidor en tiempo real
Ofrecer tecnologia para procesar datos en tiempo real y presentarlos al instante al usuario.
Cuales son tus fuentes de ingresos?
SaaS Software as a Service
@dcadenas
dcadenas / templatemethod.go
Created December 2, 2011 23:04
"Template method" in Go
package main
type IChild interface {
Describe()
PrintName()
}
type Base struct { child IChild }
func (b *Base)Describe(){
println("I'm a child of Base")
@dcadenas
dcadenas / article.rb
Created February 24, 2012 17:59 — forked from foca/article.rb
Help me clean this up so one scope uses the other!
# I have this AR model that has two scopes that should return complementary sets
# of rows: one returns all the rows that match certain conditions, the other
# returns all rows that DON'T match the same conditions.
#
# I would like to build the second scope using the first one. Something like:
#
# class Article
# def self.problematic
# not(complete)
# end