Skip to content

Instantly share code, notes, and snippets.

View orlando's full-sized avatar
🦅

Orlando Del Aguila orlando

🦅
View GitHub Profile
@orlando
orlando / database.rb
Created June 28, 2011 19:08 — forked from jacquescrocker/database.rb
configures padrino to use config/mongoid.yml
# config/database.rb
config_file = Padrino.root("config", "mongoid.yml")
if File.exists?(config_file)
settings = YAML.load(ERB.new(File.read(config_file)).result)[Padrino.env.to_s]
::Mongoid.from_hash(settings) if settings.present?
end
@orlando
orlando / gist:1085657
Created July 15, 2011 22:06
devise I18n file in spanish
es:
errors:
messages:
expired: "has expired, please request a new one"
not_found: "not found"
already_confirmed: "was already confirmed, please try signing in"
not_locked: "was not locked"
not_saved:
one: "1 error prohibited this %{resource} from being saved:"
other: "%{count} errors prohibited this %{resource} from being saved:"
@orlando
orlando / haml_converter.rb
Created July 22, 2011 04:38 — forked from radamant/haml_converter.rb
Simple haml-sass conversion for jekyll
module Jekyll
require 'haml'
class HamlConverter < Converter
safe true
priority :low
def matches(ext)
ext =~ /haml/i
end
@orlando
orlando / railscasts_downloader.rb
Created November 21, 2011 15:12
Railscasts downloader
#!/usr/bin/ruby
require 'rss'
p 'Downloading rss index'
rss_string = open('http://feeds.feedburner.com/railscasts').read
rss = RSS::Parser.parse(rss_string, false)
videos_urls = rss.items.map { |it| it.enclosure.url }.reverse
videos_filenames = videos_urls.map {|url| url.split('/').last }
@orlando
orlando / cached_event.rb
Created December 4, 2011 17:43
method missing override
# this give us activerecord like commands for events, also extend the object with the respective methods
#
# example
#
# @cachedevent.reservations return all reservations in a hash
# {"15"=>#<BSON::OrderedHash:0x-2581ca5a {values}}
#
# also extends the object with
#
# @cachedevent.reservations.extend(ReportAgregator::Reservations)
@orlando
orlando / cached_event.rb
Created December 8, 2011 15:57
Date.to_mongo
class Date
def self.to_mongo(value)
if value.nil? || value == ''
nil
else
date = value.is_a?(::Date) || value.is_a?(::Time) ? value : ::Date.parse(value.to_s)
::Time.utc(date.year, date.month, date.day, date.try(:hour), date.try(:min), date.try(:sec))
end
rescue
nil
@orlando
orlando / .bashrc
Created December 11, 2011 19:00
README.md
if [[ -n "$PS1" ]]; then
PS1='\[\033[01;30m\][ \[\033[01;31m\]\u \[\033[01;30m\]]\[\033[01;34m\]\w\[\033[00m\]\$ '
eval "`dircolors -b`"
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
fi
xhost +LOCAL:
@orlando
orlando / natcmp.rb
Created December 14, 2011 18:38
Natural Order String Comparison
# natcmp.rb
#
# Natural order comparison of two strings
# e.g. "my_prog_v1.1.0" < "my_prog_v1.2.0" < "my_prog_v1.10.0"
# which does not follow alphabetically
#
# Based on Martin Pool's "Natural Order String Comparison" originally written in C
# http://sourcefrog.net/projects/natsort/
#
# This implementation is Copyright (C) 2003 by Alan Davies
@orlando
orlando / timeslider.js
Created December 20, 2011 22:16
jquery timeslider
$("li.month").click(function(e){
e.preventDefault();
var selected_month = $(this).closest('li').index();
$("#slider-range").slider("values",[Math.abs(moment([moment().year()]).diff(moment([moment().year()]).month(selected_month-1),'month')),Math.abs(moment([moment().year()]).diff(moment([moment().year()]).month(selected_month),'days'))]);
});
@orlando
orlando / google_map.rb
Created December 25, 2011 02:52
google map
# File forked from github.com/kete/kete.. not my work
# what this does:
# * prepares google map accordingly for request type
# (form for baskets_controller#choose_type with empty map, display for index_page_controller#index,
# all other controllers#show, new, etc.)
# * adds view helpers for loading api js lib and initializing google map js and escaping js (i18n_js(key))
# * adds helpers for ExtendedFieldsHelper editor (including geocoding address form) and display
# * validates extended field ftype for map or map with address
module GoogleMap