This file contains 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
app.get '/riders', (req, res) -> | |
redis.smembers 'riders', (err, replies) -> | |
results = [] | |
build_json = (rider) -> | |
redis.hgetall rider, (err, reply) -> | |
results.push reply | |
res.json(results, 200) if results.length == replies.length | |
build_json rider for rider in replies |
This file contains 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
onscreen() | |
{ | |
if [ -z $1 ]; then | |
if [ -f $HOME/.onscreen ]; then | |
cd `cat $HOME/.onscreen` | |
else | |
echo "You must set an onscreen destination" | |
echo "cd into a directory and run 'onscreen set'" | |
fi | |
fi |
This file contains 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 User < Struct.new(:name, :phone, :email) | |
end | |
# --------------------------------------------------------------------------- | |
# Extend on demand | |
# + no dependency on User class, could be reusable | |
# + composable | |
# - cannot unextend user object once extended, but this object could be short | |
# lived | |
# --------------------------------------------------------------------------- |
This file contains 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 ProgressBar | |
def initialize(units=60) | |
@units = units.to_f | |
end | |
def print(completed, total) | |
norm = 1.0 / (total / @units) | |
progress = (completed * norm).ceil | |
pending = @units - progress | |
Kernel.print "[#{'=' * progress }#{' ' * ( pending )}] #{percentage(completed, total)}%\r" |
This file contains 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
mkdir ~/tmp_mongo_data1 | |
mkdir ~/tmp_mongo_data2 | |
mkdir ~/tmp_mongo_data3 | |
# In separate terminals | |
mongod --dbpath ~/tmp_mongo_data1 --port 5000 --replSet ben | |
mongod --dbpath ~/tmp_mongo_data2 --port 5001 --replSet ben | |
mongod --dbpath ~/tmp_mongo_data3 --port 5002 --replSet ben | |
# Then setup replication in a 4th terminal |
This file contains 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
# https://www.varnish-cache.org/docs/2.1/tutorial/vcl.html | |
# https://www.varnish-cache.org/trac/wiki/VCLExamples | |
# Summary | |
# 1. Varnish will poll the backend at /health_check to make sure it is | |
# healthy. If the backend goes down, varnish will server stale content | |
# from the cache for up to 1 hour. | |
# 2. Varnish will pass X-Forwarded-For headers through to the backend | |
# 3. Varnish will remove cookies from urls that match static content file | |
# extensions (jpg, gif, ...) |
This file contains 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 'ruby-prof' | |
# RubyProf.measure_mode = RubyProf::PROCESS_TIME | |
# RubyProf.measure_mode = RubyProf::WALL_TIME | |
# RubyProf.measure_mode = RubyProf::CPU_TIME | |
# RubyProf.measure_mode = RubyProf::ALLOCATIONS | |
# RubyProf.measure_mode = RubyProf::MEMORY | |
# RubyProf.measure_mode = RubyProf::GC_RUNS | |
# RubyProf.measure_mode = RubyProf::GC_TIME | |
result = RubyProf.profile do |
This file contains 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
desc 'Build the manual' | |
task :man do | |
require 'forker/version' | |
ENV['RONN_MANUAL'] = "Forker Manual" | |
ENV['RONN_ORGANIZATION'] = "Forker #{Forker::VERSION}" | |
sh "ronn -w -s toc -r5 --markdown man/*.ronn" | |
end |
This file contains 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
# Start a job from an SSH session that will continue to run after logging out | |
nohup ./myprogram > foo.out 2> foo.err < /dev/null & | |
# Clear memcached | |
echo flush_all | nc localhost 11211 |
This file contains 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 'rubygems' | |
require 'bundler/setup' | |
require 'eventmachine' | |
require 'httparty' | |
# Serial Processing: | |
# results = %[realtime forker].collect do |path| | |
# HTTParty.get "http://github.com/api/v2/json/repos/show/#{path}" | |
# end | |
# |