Skip to content

Instantly share code, notes, and snippets.

View lguardiola's full-sized avatar

Luis E. Guardiola lguardiola

View GitHub Profile
@lguardiola
lguardiola / string.rb
Created November 8, 2009 19:18
add n-grams capabilities to String class and calculate weights
class String
def ngram(level, *stopwords)
result = []
ranges = 0.upto(level-1).collect{|i|0..i}
data = self.gsub(/(\,|\.|\;)/,'').split.reject{|word| stopwords.flatten.include?(word)}
ranges.each do |range|
while range.max < data.size
result << data[range].join(' ')
range = range.min.succ..range.max.succ
end
@lguardiola
lguardiola / benchmark.rb
Created May 20, 2010 18:06
multiproposed benchmark module
require 'benchmark'
require 'logger'
class Module
def alias_method_chain( target, feature )
alias_method "#{target}_without_#{feature}", target
alias_method target, "#{target}_with_#{feature}"
end
end unless Module.public_method_defined?(:alias_method_chain)
@lguardiola
lguardiola / formatter.rb
Created May 27, 2010 18:02
Formatter for standard lib logger
# storage on lib/gasper/logger/formatter.rb
# Usage
# LOGGER = Logger.new('log/development.log', 'daily')
# LOGGER.formatter = Gasper::Logger::Formatter.new
# LOGGER.progname = 'mongodb-json-proxy'
#
module Gasper
module Logger
class Formatter
# YYYY:MM:DD HH:MM:SS.MS progname(pid) level: message
require "rubygems"
require "superfeedr"
require 'time'
## You can have all the XMPP logging by changing the Skates log level
Skates.logger.level = Log4r::DEBUG
##
# Don't ever forget that all this is ASYNCHRONOUS...
@lguardiola
lguardiola / rails3-base-template.rb
Created October 18, 2010 23:27
app template for rails 3, include capistrano, rspec, haml, sass, jquery and config timezone
# Usage:
# rails new YOUR_APP_NAME -m http://gist.github.com/633287.txt
#
# gems sources
add_source :gemcutter
add_source 'http://gems.github.com'
# gems
gem 'capistrano'
@lguardiola
lguardiola / application.js
Created November 17, 2010 23:56
Unobtrusive JavaScript in Rails 3
// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
jQuery.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})
$(document).ready(function() {
// All non-GET requests will add the authenticity token
// if not already present in the data packet
$(document).ajaxSend(function(event, request, settings) {
@lguardiola
lguardiola / application_4_rspec.rb
Created February 22, 2011 20:39
rails 3 template for jquery replacement
# Here is where we reap the benefits of the modularity in Rails 3.
# What this says is that we want to use RSpec as the test framework and we want to generate fixtures
# with our generated specs, but we don't want to generate view specs and
# that instead of fixtures, we actually want to use factory girl and
# we want the factories to be put into spec/factories. Whew! So does this all work?
config.generators do |generator|
generator.test_framework :rspec, :fixture => true, :views => true
generator.fixture_replacement :factory_girl, :dir => "spec/factories"
end
@lguardiola
lguardiola / migration_mongodb.rb
Created August 22, 2011 23:35
pendiente de finalizacion funcional
LETRAS='áéíóúñüça-z'
LETRASM='ÁÉÍÓÚÑÜA-Z'
# Palabra Palabra|de|del
NOMBRES_PROPIOS_RE="(?:[#{LETRASM}][#{LETRAS}#{LETRASM}]{2,}(?:[ ,](?:[#{LETRASM}][#{LETRASM}#{LETRAS}]+|(?:(?:de|la|del)(?= [#{LETRASM}])))){1,})"
class Document
include Mongoid::Document
field :title, String
field :content, String
@lguardiola
lguardiola / intendentes.csv
Created October 22, 2011 21:37
parser de municipios de argentina
PROVINCIA MUNICIPIO INTENDENTE PARTIDO POLITICO RELECTO
Buenos Aires Adolfo Alsina Alberto GUTT Frente para la Victoria Si
Buenos Aires Adolfo Gonzáles Chaves José MARTINEZ Partido Vecinal No
Buenos Aires Alberti Leonel Omar ZACCA Frente para la Victoria Si
Buenos Aires Almirante Brown Ruben Dario GIUSTOZZI Frente para la Victoria No
Buenos Aires Avellaneda Jorge FERRARESI Frente para la Victoria Si
Buenos Aires Ayacucho Dario DAVID Frente para la Victoria Si
Buenos Aires Azul Omar Arnaldo DUCLÓS Frente Coalición Cívica Si
Buenos Aires Bahía Blanca Cristian BREITENSTEIN Frente para la Victoria Si
Buenos Aires Balcarce José Enrique ECHEVERRÍA Frente para la Victoria No
# encoding: utf-8
Encoding.default_internal = "UTF-8"
Encoding.default_external = "UTF-8"
=begin
REFERENCES
ticket: https://www.pivotaltracker.com/story/show/20034615