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
#!upstart | |
description "Workers [resque]" | |
start on (local-filesystems and net-device-up IFACE=eth0) | |
stop on shutdown | |
respawn | |
respawn limit 99 5 | |
console none |
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
# 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://git.521000.bestlow | |
# gmate for gedit : https://github.com/gmate/gmate | |
# ruby dependencies | |
sudo apt-get install build-essential openssl libssl-dev libreadline6 libreadline6-dev curl |
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
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") |
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
#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 |
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
<ul> | |
<% @orders.each do |order| %> | |
<li> | |
<!-- Show order stuff --> | |
</li> | |
<% end %> | |
</ul> | |
<%= will_paginate @orders %> |
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
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 |
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
# ElasticSearch Service | |
description "ElasticSearch" | |
start on (net-device-up | |
and local-filesystems | |
and runlevel [2345]) | |
stop on runlevel [016] |
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 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 |
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
☁ 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) |
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
# 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) |
OlderNewer