Skip to content

Instantly share code, notes, and snippets.

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

Oto Brglez otobrglez

🏗️
Building.
View GitHub Profile
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",
@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 )
@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
@rmoriz
rmoriz / Gemfile
Last active February 7, 2020 12:30
UUID primary keys in Rails 3
# Gemfile
gem 'uuidtools'
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")
@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
@otobrglez
otobrglez / car.rb
Created August 23, 2011 12:26
Experimenting with observer pattern (publish/subscribe pattern) in Ruby
# 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
@scttnlsn
scttnlsn / README.md
Created July 30, 2012 22:16
Pub/sub with MongoDB and Node.js

Pub/sub with MongoDB and Node.js

Setup:

$ mongo
> use pubsub
> db.createCollection('messages', { capped: true, size: 100000 })
> db.messages.insert({})
@josevalim
josevalim / 0_README.md
Created September 13, 2012 21:52
Sinatra like routes in Rails controllers

Sinatra like routes in Rails controllers

A proof of concept of having Sinatra like routes inside your controllers.

How to use

Since the router is gone, feel free to remove config/routes.rb. Then add the file below to lib/action_controller/inline_routes.rb inside your app.

@joho
joho / gzip_net_http.rb
Created September 19, 2012 04:12
Handling gzip responses in Ruby Net::HTTP library
# from http://pushandpop.blogspot.com.au/2011/05/handling-gzip-responses-in-ruby-nethttp.html
# i wanted syntax highlighting
require 'net/http'
debug = Proc.new{|msg| STDERR.puts "[#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}] #{msg}" }
page = nil
http = Net::HTTP.new( "www.google.com", 80 )
req = Net::HTTP::Get.new( "/search?num=20&hl=en&noj=1&q=test&btnG=Search", { "Accept-Encoding" => "gzip", "User-Agent" => "gzip" } )