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
VAGRANTFILE_API_VERSION = "2" | |
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| | |
config.vm.box = "ubuntu/trusty64" | |
config.vm.provider :virtualbox do |vb| | |
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] # faster network | |
vb.memory = 1024 | |
vb.cpus = 2 | |
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
#!/bin/bash | |
export RAILS_ENV=<%= node[:application][:environment] %> | |
export PATH=$PATH:/usr/local/bin | |
APP_ROOT=<%= node[:application][:path] %>/current | |
PID=<%= node[:application][:path] %>/current/tmp/pids/unicorn.pid | |
old_pid="$PID.oldbin" |
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 'delicious' | |
require 'json' | |
require 'csv' | |
TAGS_FILE = 'tags.json' | |
EDGES_FILE = 'tags.csv' | |
def get_tags | |
cache_tags unless File.exist?(TAGS_FILE) | |
JSON.parse(File.read(TAGS_FILE)) |
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
Searching for 648248 in sorted array | |
user system total real | |
linear 34.070000 0.040000 34.110000 ( 34.127835) | |
native binary 0.000000 0.000000 0.000000 ( 0.000203) | |
binary recursive 0.000000 0.000000 0.000000 ( 0.000334) | |
binary iterative 0.000000 0.000000 0.000000 ( 0.000258) |
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 RomanToInt | |
def initialize(roman) | |
@roman = roman.downcase | |
end | |
def to_int | |
result = 0 | |
roman = @roman | |
exceptions.each do |exception, exception_value| |
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 MyHashMap | |
BUCKETS = 100 | |
attr_reader :iterations | |
def initialize | |
@values = [] | |
@iterations = 0 | |
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
%i(net_http em_http typhoeus).each do |method| | |
Benchmark.bm(15) do |x| | |
(5..100).step(5) do |c| | |
x.report("#{method} #{c}") { send("download_#{method}", urls, c) } | |
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
require 'typhoeus' | |
def download_typhoeus(urls, concurrency) | |
hydra = Typhoeus::Hydra.new(max_concurrency: concurrency) | |
urls.each do |url| | |
request = Typhoeus::Request.new url | |
request.on_complete do |response| | |
write_file url, response.body | |
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
require 'em-http' | |
def download_em_http(urls, concurrency) | |
EventMachine.run do | |
multi = EventMachine::MultiRequest.new | |
EM::Iterator.new(urls, concurrency).each do |url, iterator| | |
req = EventMachine::HttpRequest.new(url).get | |
req.callback do | |
write_file url, req.response |