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 Array | |
# Converts [[k1,v1],[k2,v2]] into {k1 => v1, k2 => v2} | |
# The opposite of Hash#to_a | |
# Same as `Hash[ary.flatten]` | |
def to_h | |
inject({}) {|h,el| h[el[0]] = el[1]; h } | |
end | |
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
#/bin/bash | |
# Builds a gc patched ruby according to: | |
# http://guides.rubyonrails.org/benchmarking_and_profiling.html#_performance_test_cases | |
mkdir ${HOME}/rubygc | |
mkdir -p ${HOME}/src | |
# 1. Compile | |
echo "-- compiling ruby from source with gc patch --" | |
cd ${HOME}/src |
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}" |
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
=== Epic Snow Leopard Upgrayyyyd Guide === | |
More info here: http://www.gregbenedict.com/2009/08/29/fixing-ruby-gems-mysql-and-passenger-phusion-on-snow-leopard-10-6/ | |
Son, you’re now living in the land of 64-bit systems. | |
That means that some of your 32-bit shit is now broken. | |
Not all is lost. |
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
Example for .bashrc: | |
export LSCOLORS="exfxcxdxbxegedabagacad" | |
a black | |
b red | |
c green | |
d brown | |
e blue | |
f magenta | |
g cyan |
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
sudo atsutil databases -remove | |
atsutil server -shutdown | |
atsutil server -ping |
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 AverageTimeOfDay | |
require 'date' | |
# Assumes times_of_day is an array of valid time strings in chronological | |
# order. | |
def average_time_of_day(times_of_day) | |
# Convert times_of_day to an array of Time objects, ensuring that times | |
# are in chronological order by adding a day if the the time of the | |
# current iteration is earlier than the last iterated time. | |
times = times_of_day.inject([]) do |times, time_of_day| | |
dt = DateTime.strptime(time_of_day, "%I:%M%p") |
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
# This is a skeleton for a daemon process that behaves well in | |
# a unix environment. | |
# Fork a child process and exit the parent | |
exit(0) if Process.fork | |
# Trap the signal sent by the kill command | |
trap("SIGTERM") { Syslog.warning("I died"); exit(0) } | |
# Establish this process as a new session and process group leader, |
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
require 'set' | |
class ClosedCircuit | |
Infinity = 1/0.0 | |
def initialize(input, source, dest) | |
@graph = GraphParser.parse(input) | |
@source = source | |
@dest = dest | |
end |
OlderNewer