Skip to content

Instantly share code, notes, and snippets.

View otobrglez's full-sized avatar
🏗️
Building.

Oto Brglez otobrglez

🏗️
Building.
View GitHub Profile
@otobrglez
otobrglez / as3.rake
Created June 29, 2011 13:40
Rake task for uploading Rails 3.1 compiled assets to Amazon S3 storage
# 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
scope :ordered_by_article_count,
select("users.*, c.count as article_count").
joins("LEFT JOIN (SELECT user_id, COUNT(user_id) as count
FROM articles WHERE state = 'active' GROUP BY user_id) as c ON c.user_id = users.id").
where("c.count IS NOT NULL").
order("c.count DESC")
@rmoriz
rmoriz / Gemfile
Last active February 7, 2020 12:30
UUID primary keys in Rails 3
# Gemfile
gem 'uuidtools'
@jeroenroodnat
jeroenroodnat / gist:849669
Created March 1, 2011 19:08
Mongo Geonear with Mongoid rough hack
query = BSON::OrderedHash.new.tap do |query|
query["geoNear"]="locations"
query["near"] = lon_lat
end
lon,lat =lon_lat
query = Location.collection.db.command(query)['results'].sort_by do |r|
r['distance'] = Haversine.distance(lat,lon,r['obj']['lon_lat'][1],r['obj']['lon_lat'][0])
end
@otobrglez
otobrglez / economics.rb
Created December 23, 2010 11:23
Economics challenge for (RPCFN: Economics 101 (#13)) - Oto Brglez
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 )
require 'rubygems'
require 'eventmachine'
require 'feedzirra'
require 'restclient'
feeds_url = [ "http://stackoverflow.com/feeds/tag/ruby-on-rails",
"http://stackoverflow.com/feeds/tag/ruby",
"http://stackoverflow.com/feeds/tag/git",
"http://stackoverflow.com/feeds/tag/mongodb",
"http://stackoverflow.com/feeds/tag/nginx",