This file contains hidden or 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
require 'nokogiri' | |
class World | |
attr_reader :continents | |
def initialize(world_xml="cia-1996.xml") | |
@continents = [] | |
if File.exists?(world_xml) | |
@noko = Nokogiri::XML(File.open world_xml ) |
This file contains hidden or 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
# 1) Put 's3' gem in Gemfile. | |
# 2) Create as3.yml configuration for S3 | |
# 3) Create initializer for as3.yml | |
# 4) Make "assets" folder inside your bucket | |
# 5) After running task run "RAILS_ENV=production rake assets:precompile" | |
# 6) Invoke task by running "rake as3:upload" | |
namespace :as3 do | |
desc "Uploads compiled assets (public/assets) to Amazone AS3" | |
task :upload do |
This file contains hidden or 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 Importer | |
attr_accessor :db | |
def initialize(db="#{Rails.root}/db/base-5-7-2011.sqlite3") | |
self.db = SQLite3::Database.new(db) | |
end | |
def import_articles | |
articles = @db.execute(" | |
SELECT |
This file contains hidden or 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 method finds related articles using Jaccard index (optimized for PostgreSQL). | |
# More info: http://en.wikipedia.org/wiki/Jaccard_index | |
class Article < ActiveRecord::Base | |
def related(limit=10) | |
Article.find_by_sql(%Q{ | |
SELECT | |
a.*, | |
( SELECT array_agg(t.name) FROM taggings tg, tags t |
This file contains hidden or 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
# Simple Car class. Nothing special here... | |
class Car | |
attr_accessor :brand | |
attr_accessor :model | |
attr_accessor :year | |
def initialize(brand, model, year=2011) | |
@brand, @model, @year = brand, model, year | |
end | |
This file contains hidden or 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
# By Oto Brglez - @otobrglez | |
# Rake task. Put in your (lib/tasks) folder of your Rails application | |
# Execute with "rake dropbox:backup" | |
# Configuration must be inside config/dropbox.yml file | |
namespace :dropbox do | |
desc "Backup production database to dropbox" | |
task :backup do | |
This file contains hidden or 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
Note that scopes defined with scope will be evaluated when they are defined, rather than when they are used. For example, the following would be INCORRECT!!!: | |
scope :published, | |
where(:published => 1) | |
.where(:hidden => 0) | |
.where("publish_date <= ?", Time.now) | |
The example above would be "frozen" to the Time.now value when the model class was defined, and so the resultant SQL query would always be the same. The correct way to do this would be via a lambda, which will re-evaluate the scope each time it is called: | |
scope :published, -> { |
This file contains hidden or 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
# Playing with blocks :) | |
class Integer | |
def times(&block) | |
(0...self).each do |i| | |
block.call i | |
end | |
end | |
end |
This file contains hidden or 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
#!/usr/bin/env ruby | |
require "nokogiri" | |
require "pathname" | |
require "date" | |
gpx_root_folder = "/"+["Users", ENV["USER"], "mainnav-tracklogs"].join("/") | |
if ARGV[0].nil? or ARGV[1].nil? | |
puts "Missing dates!" |
OlderNewer