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 'redis' | |
# This is a direct port of ActiveSupport::Cache::MemCacheStore | |
# Drop this file in lib/active_support/cache/redis_store and in your env files | |
# add: | |
# | |
# config.cache_store = :redis_store | |
module ActiveSupport | |
module Cache |
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 SysAdmin | |
class Dsl | |
def self.evaluate(file) | |
builder = new | |
builder.instance_eval(file.read, "config", 1) | |
builder.to_definition | |
end | |
def initialize | |
@servers = [] |
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 'capistrano' | |
unless Capistrano::Configuration.respond_to?(:instance) | |
abort "capistrano/ext/multiserver requires Capistrano 2" | |
end | |
# Example Usage: | |
# servers.define :app1, '[email protected]', :port => 9999 | |
# servers.define :app2, '[email protected]', :port => 9999 | |
# servers.define :db1, '[email protected]', :port => 9999 | |
# servers.define :db2, '[email protected]', :port => 9999 |
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
# Goal: | |
# Authenticate a params hash with an authenticity_token | |
require 'openssl' | |
secret = "9d0d287c71f2e2629ca34bdbc03772509b815a4d2ad6392c7a436249698a29f34d2883d3cb640d9fbdd0a7fc45b42c6fa293d6119d97aeb324c0b1eeafb51e19" | |
params = {:a => 'a', :b => 'b', :c => 'b'} | |
params[:_authenticity_token] = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('SHA1'), secret, params.values.join) | |
p params |
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
#!/bin/bash | |
PROGNAME="/app/script/delayed_job" | |
RAILS_ENV="production" | |
USER="user" | |
HOME="/home/user" | |
start() { | |
echo "Starting $PROGNAME" | |
sudo -u $USER /usr/bin/env HOME=$HOME RAILS_ENV=$RAILS_ENV $PROGNAME start | |
} |
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 'ruport' | |
t = Table(%w[date vert a b]) | |
t << ["2010-01-01", "life",10,20] | |
t << ["2010-01-01", "life",10,20] | |
t << ["2010-01-02", "life",10,20] | |
t << ["2010-01-03", "life",10,20] | |
t << ["2010-01-04", "life",10,20] | |
t << ["2010-01-01", "health",10,20] |
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 "net/http" | |
http = Net::HTTP.new("example.com") | |
http.open_timeout = 2 | |
http.read_timeout = 3 # Must be greater than open_timeout | |
begin | |
http.start | |
begin | |
http.request_get("/whatever?") do |res| | |
res.read_body | |
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
class Hash | |
def map | |
inject({}) { |memo,(k,v)| memo[k] = yield(v); memo } | |
end | |
end | |
def past(interval) | |
interval.map { |v| v.abs * -1 } | |
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
module Bitmap | |
def self.bgr_to_rgba(raw_bgr_array, width, height, new_dimension) | |
width_padding = new_dimension - width | |
height_padding = new_dimension - height | |
# First convert to array of Pixel::BGR objects | |
raw_bgr_array.enum_for(:each_slice, 3).map { |a| Pixel::BGR.new(*a) }. | |
reverse. # Reverse it | |
map { |bgr| bgr.to_rgba }. # Map to array of Pixel::RGBA objects | |
enum_for(:each_slice, width).inject([]) { |memo, row| memo << row }. # Create a 2d array based on width |