Skip to content

Instantly share code, notes, and snippets.

View dcadenas's full-sized avatar

Daniel Cadenas dcadenas

View GitHub Profile
@dcadenas
dcadenas / goopening.rb
Created July 8, 2012 10:24
Script to explore chess opening lines based on most popular google results
#!/usr/bin/env ruby
#Script to explore chess opening lines based on most popular of google's top 100 results
#Usage:
#▸ ./goopening "1. e4 e5 2."
#1: nf3 (35)
#2: qh5 (7)
#3: bc4 (4)
#4: nc6 (2)
@dcadenas
dcadenas / checkbug.rb
Created July 4, 2012 20:30
Script to check bug in mac's ssl
#!/usr/bin/env ruby
require 'net/https'
require 'open-uri'
require 'tempfile'
# This script tries to detect a bug in which macosx doesn't raise an exception
# and executes the request despite knowing the host failed its ssl verification
#
# Run with ruby < <(curl -s https://raw.github.com/gist/3049397/checkbug.rb)
# Try it in linux and macosx. Linux behaves correctly.
@dcadenas
dcadenas / verifyssl.rb
Created July 4, 2012 06:28
Script to verify ssl hosts and pem files.
#!/usr/bin/env ruby
require 'net/https'
require 'open-uri'
require 'tmpdir'
unless ARGV[0]
puts "Usage: #{File.basename(__FILE__)} hostname [pemfile]"
puts "It will use http://curl.haxx.se/ca/cacert.pem if no pemfile is specified"
exit false
@dcadenas
dcadenas / rspec_metadata.rb
Created June 21, 2012 07:07
Doubt about RSpec metadata
#Which is the best alternative? A is clearer but is it slower? is there a better way?
#A: The block will be run in all examples, do_something_with will only be run when my_metadata defined
RSpec.configure do |config|
config.before(:each) do |example|
do_something_with(example.metadata[:my_metadata]) if example.metadata.has_key?(:my_metadata)
example.run
end
end
@dcadenas
dcadenas / gist:2222145
Created March 28, 2012 00:34
Popular Uruguayan githubbers
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'rankable_graph'
require 'net/http'
require 'mechanize'
require 'nokogiri'
def follower_usernames_of(user)
@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
@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 / 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 / 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: ->