Skip to content

Instantly share code, notes, and snippets.

View dcadenas's full-sized avatar

Daniel Cadenas dcadenas

View GitHub Profile
@dcadenas
dcadenas / Guardfile
Last active December 23, 2015 09:59
Poor man's livereload for Mac + Chrome
require 'guard'
require 'guard/guard'
module ::Guard
class Reload < Guard
def initialize(*args, &block)
super
@script = <<-APPLESCRIPT
tell window 1 of application "Google Chrome"
#! /usr/bin/env ruby
#usage: imsg daniel "hello world"
buddyids = {
daniel: "dcadenas@gmail.com",
elcuervo: "yo@brunoaguirre.com"
}
nickname = ARGV[0].to_sym
@dcadenas
dcadenas / pre-commit
Created October 16, 2012 16:31
Pre commit hook to avoid commiting badly named rspec files
#!/usr/bin/env ruby
test_dirs = %w[configurations
lib
modules
services
uploaders
controllers
helpers
mailers
presenters
@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:2325686
Created April 7, 2012 05:56
Javascript de bookmarklet para poner ratings IMDB y rotten tomatoes en cartelera.com.uy
(function(){
var putRatings = function($){
$('.peli_izq .cinesala').each(function(_,link){
var escapedTitle = escape(link.text.trim());
if(escapedTitle !== ""){
$.getJSON("http://www.imdbapi.com/?t=" + escapedTitle + "&tomatoes=true&y=" + (new Date().getFullYear()) + "&callback=?", function(d){
if(d.imdbRating) {
$(link).after('<div style="float:right; background:yellow; line-height:8px; border:solid; padding:3px">\
<p>Búsqueda en IMDB<\p>\
@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