Skip to content

Instantly share code, notes, and snippets.

unless ARGV[0].nil?
File.open(ARGV[0],'r').each do |line|
line.gsub!(/\(|\)|,/,'')
versions = line.split
gem_name = versions.shift
versions.each do |version|
puts "gem install #{gem_name} -v=#{version} --ignore-dependencies"
system("gem install #{gem_name} -v=#{version} --ignore-dependencies")
@brenes
brenes / lastfm-very-simple-recommender.rb
Created March 22, 2011 21:08
SImple and nasty song recommender for lastfm
# This script just get the latest tracks of your friends on Last.fm and recommends those more popular.
# It's all based on a conversation between @mort, @rochgs, @littlemove and me (mainly by @mort)
# INSTRUCTIONS
# 1. Install lastfm gem: https://github.com/youpy/ruby-lastfm/
# gem install lastfm
# 2. Get a Last.fm API Key on http://www.lastfm.es/api
require 'lastfm'
@brenes
brenes / render_json_temp.js
Created May 27, 2011 11:11
Tiny JQuery extension to render json over an element using Tempo
$(function(){
(function($) {
$.fn.render_json = function (url, data_to_send) {
$.ajax({url: url, dataType: 'json', data: data_to_send, context: $(this),
success: function(data_received){
if(data_received.length > 0)
{
$(this).each(function () {
Tempo.prepare(this.id).render(data_received);
});
@brenes
brenes / survey_2007_elections_scrapping.rb
Created June 8, 2011 23:06
Scrapping some survey data on spanish elections (2007)
require 'rubygems'
require 'nokogiri'
require 'open-uri'
# SOME CONFIG STUFF ###########################################################
survey_urls = {
"Aragón" => "http://www.cis.es/cis/opencms/-Archivos/Marginales/2680_2699/2687/e268700.html",
"Asturias" => "http://www.cis.es/cis/opencms/-Archivos/Marginales/2680_2699/2688/e268800.html",
"Baleares" => "http://www.cis.es/cis/opencms/-Archivos/Marginales/2680_2699/2689/e268900.html",
@brenes
brenes / colorize_git_ps1.bash
Created June 14, 2011 13:51 — forked from afgomez/colorize_git_ps1.bash
Color current git branch in prompt
# Color the current git branch in prompt
# red -> we are in master, take care!
# blue -> just a normal branch. Carry on
function __colorize_git_ps1 () {
local branch=$(__git_ps1 "%s")
if [ -n "$branch" ]; then
local color
if [[ $branch == master* ]]; then
color="31" #Red
@brenes
brenes / README.md
Last active September 15, 2025 06:38
CSV de paises, con nombre en castellano, ingles, codigo ISO y prefijo telefónico del país
@brenes
brenes / jquery.select_linker.js
Created August 5, 2011 12:07
Script used to link two selects acording to some options
/*
Select Linker: This extension links two selects so the options loaded depends on each select.
How to use it:
> options = {"__default" : ...}
> $("#select_one").link_select("#select_two", options, false);
Params:
* other_select : Selector to reach other select
@brenes
brenes / execute_rake.rb
Created August 20, 2011 09:35
Código para ejecutar una tarea rake desde ruby (para tests, por ejemplo)
# Source: http://stackoverflow.com/questions/1255176/test-rake-tasks
def execute_rake(file,task)
require 'rake'
rake = Rake::Application.new
Rake.application = rake
Rake::Task.define_task(:environment)
load "#{Rails.root}/lib/tasks/#{file}"
rake[task].invoke
end
@brenes
brenes / custom_steps.rb
Created August 25, 2011 11:42
Pequeño hack de MundoPepino para soportar multisite
# Yo tengo un modelo site con la información de los sites (dominios) de mi aplicación
# Si esa información estuviera en un fichero de configuración o algo habría que cambiar esto.
Dado /^que estamos en el site "(.+)"$/ do |site_name|
site = Site.find_by_title site_name
MundoPepino.world.host = site.host
end
@brenes
brenes / info_boxes_wikpiedia_regexp.rb
Created September 8, 2011 13:30
Removing infoboxes from Wikipedia pages with a regexp
# INFO extracted from : http://stackoverflow.com/questions/6331065/matching-balanced-parenthesis-in-ruby-using-recursive-regular-expressions-like-pe
require 'wikipedia'
wikipage = Wikipedia.find(title)
# This regular expression is not valid for infoboxes with '}' (i.e: http://en.wikipedia.org/wiki/The_Royal_Anthem_of_Jordan)
no_infoboxes = wikipage.content.gsub(/\{\{[^\}]*\}\}/, "")
# This regular expression makes use of recursive regular expressions so now handles recursive {{}} structures
no_infoboxes = wikipage.content.gsub(%r{(?<re>\{\{(?:(?> [^\{\}]+ )|\g<re>)*\}\})}x, "")