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
# 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
# Making a large class modular | |
# * Put core functionality into Base module inside your class | |
# * Split other functionality into modules and include them at the bottom of the | |
# your class | |
# * Now it is easy to reuse or recreate custom versions of the class by creating | |
# new classes, including only some modules, swapping modules out for others, etc. | |
class MainClass | |
module Base | |
attr_accessor :name | |
def initialize(name) |
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 'active_record' | |
ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":memory:" | |
ActiveRecord::Schema.define do | |
create_table :authors do |t| | |
t.string :name, :null => false | |
end | |
add_index :authors, :name, :unique |
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
# set PATH so it includes user's private bin if it exists | |
if [ -d "$HOME/bin" ] ; then | |
PATH="$HOME/bin:$PATH" | |
fi | |
# rbenv support | |
if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi | |
# If not running interactively, don't do anything | |
[ -z "$PS1" ] && return |
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
module Rack | |
# Renders a valid robots.txt according to http://www.robotstxt.org | |
# This is an example of over-engineering. But it's simple example of | |
# how you might test your middleware. | |
class RobotsTxt | |
def initialize(app) | |
@app = app | |
end | |
def call(env) |
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
#!/bin/bash | |
# a quick and dirty backup script. | |
# if you have a websites folder and some databases to backup | |
# this script might be a good starting point. | |
# this script assumes you have user named admin. | |
BASE_DIR='/' | |
TARGET_DIR='sites' | |
BACKUP_TIME=`date +%Y%m%d%H%I%S` | |
BACKUP_FILENAME="${BACKUP_TIME}-${TARGET_DIR}" |
NewerOlder