This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActionController::Base | |
# Modified version of caches_page to allow specifiying an :expire_after | |
# such that the page will be expired via a background job | |
# Example: | |
# class PostsController < ApplicationController | |
# time_caches_page :index, :expire_after => 5.minutes | |
# . | |
# . | |
# end | |
def self.time_caches_page(*actions) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module JavascriptsHelper | |
# This helper yeilds contents to 2 places that should be available | |
# in the application layout. One for including javascript files, | |
# the other is for including initialization codes. The layout should have | |
# something as follows: | |
# <%= yield :javascripts %> | |
# <script type="text/javascript"> | |
# $(function({ | |
# <%= yield :javascripts_ready %> | |
# })); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A simple class trying to solve the issue of defining constants in a ruby application. | |
# I have always tended to define constants I use as Hashes as follows | |
# PersonTypes = {:good_guy => 1, :super_hero => 2} | |
# But the moment I needed to add more attributes, things Got Ugly | |
# PersonTypesInfo = {:good_guy => {:id => 1, :name => "Mr Good Guy"}, | |
# :super_hero => {:id => 2, :name => "Mr Hero"}} | |
# So, here's a simple class that initializes constants that hold attributes | |
# and enable you to retreive them in different ways like getting all of them | |
# or oredring them by one of the attributes | |
# Example usage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# obtained from http://snippets.dzone.com/posts/show/1727 | |
# for the complete list (http://en.wikipedia.org/wiki/ISO_3166-1) | |
class CreateCountries < ActiveRecord::Migration | |
def self.up | |
create_table :countries do |t| | |
t.column :iso, :string, :size => 2 | |
t.column :name, :string, :size => 80 | |
t.column :printable_name, :string, :size => 80 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a port of the javascript code found in the following link | |
#http://groups.google.com/group/Google-Maps-API/browse_thread/thread/a45947d72c27cc73 | |
class Mercator | |
#offset is defined at zoom level 21 which means that this Mercator is valid for 21 zoom levels | |
OFFSET = 268435456 | |
RADIUS = OFFSET / Math::PI | |
def self.lng_to_x(lng, zoom) | |
(OFFSET + RADIUS * lng * Math::PI / 180).to_i >> (21 - zoom) |