Skip to content

Instantly share code, notes, and snippets.

View javier's full-sized avatar

javier ramírez javier

View GitHub Profile
module RouteTranslation
mattr_accessor :translations
mattr_accessor :reverse_translations
rf=File.join(RAILS_ROOT,'config','route_translation.yml')
self.translations=YAML.load_file(rf)
self.reverse_translations=Hash.new
translations.keys.each do |key|
self.reverse_translations.merge! translations[key].invert
namespace :mysql do
# Parameter 'days' indicates maximum inactivity days before deletion. Default is 30
desc "cleanup old sessions from the database"
task :expire_sessions => :environment do
days = ENV['days'] || 30
ActiveRecord::Base.connection.execute "delete from sessions where datediff(utc_date(),updated_at) > #{days}"
puts "Sessions idle more than #{days} days expired"
puts "Anonymous sessions expired"
end #task do
Hash.class_eval do
def deep_select(key)
res=[]
res << self[key]
values.select{|v| v.is_a?(Hash)}.each do |h|
children=h.deep_select(key)
res += children if children
end
res.compact!
res.empty? ? nil : res
require 'net/http'
require 'uri'
def _post(url, params)
url+="/" unless url =~ /\/$/
Net::HTTP.post_form(URI.parse(url),params)
end
#!/usr/bin/ruby1.8
#
# This file was generated by RubyGems.
#
# The application 'rails' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
@font-face {
font-family: 'Essays1743Italic';
src: url('Essays1743-Italic.eot');
src: local('☺'), url('Essays1743-Italic.ttf') format('truetype');
}
@font-face {
font-family: 'Essays1743Medium';
src: url('Essays1743.eot');
src: local('☺'), url('Essays1743.ttf') format('truetype');
module Categorizable
module ClassMethods
def acts_as_categorizable
has_many :audience_scopes, :as => :audienciable
has_many :audience_categories, :through => :audience_scopes
has_many :areas, :through => :audience_scopes
@javier
javier / gist:827358
Created February 15, 2011 10:21
kaminari ultrasphinx
#kaminari uses different method names than will:paginate, but with a small add-on
#we can use it for paginating thinking sphinx results
ThinkingSphinx::Search.class_eval do
def num_pages
total_pages
end
def limit_value
per_page
end
@javier
javier / jazzfonica.rb
Created June 14, 2011 11:29 — forked from ace/jazzfonica.rb
jazzfonica
#!/usr/bin/env ruby
# jazzfonica.rb for Mac OS X
# Scans the visible networks for JAZZTEL_XXXX or WLAN_XXXX and calculates the password
# Ported from PHP example at http://kz.ath.cx/wlan/codigo.txt
# Download and execute with ruby (e.g. ruby jazzfonica.rb) from a Terminal
#ported to ubuntu from https://gist.github.com/1024587
#it will ask for sudo privileges.
#if your wlan card is not "wlan0" change the "my_wifi_card" variable