Skip to content

Instantly share code, notes, and snippets.

View lguardiola's full-sized avatar

Luis E. Guardiola lguardiola

View GitHub Profile
@lguardiola
lguardiola / Dockerfile
Last active August 29, 2015 14:25 — forked from inkel/Dockerfile
FROM alpine:3.2
MAINTAINER Leandro López <inkel.ar@gmail.com>
# Install base packages
RUN apk update && apk upgrade
# Install ruby and ruby-bundler
RUN apk add curl-dev ruby-dev build-base ruby
# Clean APK cache
@lguardiola
lguardiola / testHook.js
Created August 20, 2015 15:55
My first hook.io microservice
module['exports'] = function simpleHttpRequest (hook) {
// npm modules available, see: http://hook.io/modules
var request = require('request');
request.get('http://httpbin.org/ip', function(err, res, body){
if (err) {
return hook.res.end(err.messsage);
}
hook.res.end(body);
})
};
@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