Skip to content

Instantly share code, notes, and snippets.

@andreacfm
andreacfm / resque_worker_upstart.sh
Created October 3, 2011 15:33
resque workers via upstart runned by unpriviledge user
#!upstart
description "Workers [resque]"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
respawn
respawn limit 99 5
console none
@linuxbender
linuxbender / install-rvm-rubyonrails.bash
Created October 9, 2011 18:31
Install rvm rubyonrails 3.1.1 linux (ubuntu in my case)
# rvm homepage :http://beginrescueend.com/
# rubyonrails homepage :http://rubyonrails.org/
# using gemset : http://beginrescueend.com/gemsets/using/
# js env : https://github.com/sstephenson/execjs
# heroku hosting : http://www.heroku.com/
# github repo : https://github.comlow
# gmate for gedit : https://github.com/gmate/gmate
# ruby dependencies
sudo apt-get install build-essential openssl libssl-dev libreadline6 libreadline6-dev curl
@ajokela
ajokela / distance.rb
Created October 16, 2011 20:53
Ruby/Rails - Distance between latitude/longitude points
GeoName.find_by_sql("SELECT ordered.* FROM (SELECT gn.*, round(distance.d * 6371.0, 2) AS distance_km, round(distance.d * 6371.0 * 0.621371192, 2) as distance_miles FROM
(SELECT (2*atan2(sqrt(calcs.a), sqrt(1-calcs.a)))::numeric d, calcs.id FROM
(SELECT (sin(consts.dlat/2) * sin(consts.dlat/2) + sin(consts.dlon/2) * sin(consts.dlon/2) * cos(consts.lat1) * cos(consts.lat2)) as a, consts.id FROM
(SELECT f.id, abs((#{self.exif_data.latitude} - f.latitude)*(#{Math::PI}/180)) AS dlat,
abs((#{self.exif_data.longitude} - f.longitude)*(#{Math::PI}/180)) AS dlon,
#{self.exif_data.latitude} * (#{Math::PI}/180) as lat1,
f.latitude * (#{Math::PI}/180) as lat2 FROM geo_names f) consts) calcs) distance,
geo_names gn WHERE gn.id = distance.id ORDER BY distance.d ASC LIMIT 10) ordered ORDER BY random() LIMIT 1")
@boriscy
boriscy / install-ruby-debug-ubuntu-ruby-1.9.3
Created November 1, 2011 18:57
ruby-debug in ruby-1.9.3 and ubuntu
#To install ruby-debug on Ubuntu ruby-1.9.3 you need to download from http://rubyforge.org/frs/?group_id=8883
linecache19-0.5.13.gem
ruby_core_source-0.1.5.gem
ruby-debug19-0.11.6.gem
ruby-debug-base19-0.11.26.gem
#Then in your console
export RVM_SRC=/your/path/to/ruby-1.9.3
@yrgoldteeth
yrgoldteeth / _orders.html.erb
Created November 11, 2011 03:34 — forked from gonzedge/_orders.html.erb
Rails 3.1 - will_paginate and ajax
<ul>
<% @orders.each do |order| %>
<li>
<!-- Show order stuff -->
</li>
<% end %>
</ul>
<%= will_paginate @orders %>
@kapkaev
kapkaev / config-initializers-resque.rb
Created November 19, 2011 15:25 — forked from andreaseger/config-initializers-resque.rb
carrierwave resque background image processing foo
rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..'
rails_env = ENV['RAILS_ENV'] || 'development'
resque_config = YAML.load_file(rails_root + '/config/resque.yml')
Resque.redis = resque_config[rails_env]
#secure the admin view of resque
Resque::Server.use(Rack::Auth::Basic) do |user, password|
password == "secret"
end
@tobiasmcnulty
tobiasmcnulty / elasticsearch.conf
Created January 22, 2012 22:07 — forked from rbscott/elasticsearch.conf
upstart job for elastic search
# ElasticSearch Service
description "ElasticSearch"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
@wycats
wycats / 0_app.rb
Created April 19, 2012 10:22
Example of using a simple future library for parallel HTTP requests
class TicketsController < ApplicationController
def show
tickets = params[:tickets].split(",")
ticket_data = tickets.map do |ticket|
parallel { Faraday.get("http://tickets.local/#{ticket}") }
end
render json: { tickets: ticket_data.map(&:result) }
end
@hakanensari
hakanensari / Results
Created July 9, 2012 21:07
Benchmarking Ruby SAX parsing with Ox and Nokogiri
☁ code ruby sax_parsers.rb
Rehearsal --------------------------------------------
ox 0.800000 0.020000 0.820000 ( 0.820952)
nokogiri 2.110000 0.020000 2.130000 ( 2.144550)
----------------------------------- total: 2.950000sec
user system total real
ox 0.790000 0.010000 0.800000 ( 0.808858)
nokogiri 2.080000 0.030000 2.110000 ( 2.239248)
@danneu
danneu / benchmark
Created October 29, 2012 23:04
Ox vs Nokogiri: DOM and SAX parsing comparison
# I'm no benchmark guru. Just did a bunch of:
$ time ruby <filename>
# Note: This is just an 80mb XML file with 38,000 nodes.
ox_dom.rb 4.56s user 0.78s system 93% cpu 5.714 total (550mb)
ox_dom.rb 4.58s user 0.79s system 87% cpu 6.126 total (550mb)
ox_dom.rb 4.60s user 0.80s system 87% cpu 6.140 total (550mb)
nokigiri_dom.rb 11.75s user 1.02s system 94% cpu 13.518 total (895mb)
nokigiri_dom.rb 11.36s user 1.02s system 93% cpu 13.211 total (895mb)