Skip to content

Instantly share code, notes, and snippets.

View woods's full-sized avatar

Scott Woods woods

View GitHub Profile
@woods
woods / working_hours.rb
Created July 20, 2011 17:32
Calculating elapsed working days / hours
>> d1 = Date.new( 2006, 12, 1 )
=> #<Date: 4908141/2,0,2299161>
>> d2 = Date.new( 2007, 1, 15 )
=> #<Date: 4908231/2,0,2299161>
>> (d1..d2)
=> #<Date: 4908141/2,0,2299161>..#<Date: 4908231/2,0,2299161>
>> weekends = [0, 6]
=> [0, 6]
>> (d1..d2).each { |i| puts i }
<snip>
@woods
woods / sessions.php
Created October 14, 2011 03:06
Learning about PHP sessions
<?php
if ( array_key_exists('sname', $_REQUEST) ) {
session_name($_REQUEST['sname']);
}
session_start();
$messages = "";
function show( $str ) { global $messages; $messages .= $str; }
function show_sess_vars() {
foreach ( $_SESSION as $key => $val ) {
@woods
woods / twighlighted.xml
Created October 14, 2011 03:08
Twighlight theme for PHPStorm IDE
<?xml version="1.0" encoding="UTF-8"?>
<scheme name="Twilighted" version="1" parent_scheme="Default">
<option name="LINE_SPACING" value="1.2" />
<option name="EDITOR_FONT_SIZE" value="12" />
<option name="EDITOR_FONT_NAME" value="Monaco" />
<colors>
<option name="ANNOTATIONS_COLOR" value="3e83e7" />
<option name="CARET_COLOR" value="ffff99" />
<option name="CARET_ROW_COLOR" value="" />
<option name="CONSOLE_BACKGROUND_KEY" value="1a1a1a" />
@woods
woods / bootstrap_chef_server.sh
Created December 17, 2011 13:33
Set up rackspace cloud server as chef server
#!/bin/bash
set -e # Exit on error
set -x # Print each command
# Set up the OpsCode repository
echo "deb http://apt.opscode.com/ `lsb_release -cs`-0.10 main" | tee /etc/apt/sources.list.d/opscode.list
gpg --keyserver keys.gnupg.net --recv-keys 83EF826A
gpg --export [email protected] | tee /etc/apt/trusted.gpg.d/opscode-keyring.gpg
apt-get update
@woods
woods / existing_ruby_class.rb
Created March 6, 2012 21:43
Read existing Ruby source files into their own namespace after the fact
class A
@counter = 0
def self.inc
@counter += 1
end
end
@woods
woods / example.rb
Created May 8, 2012 03:05
How to dynamically query enum values from Postgresql in Rails
sql = %{
select enumlabel
from pg_enum
where enumtypid = 'company_status'::regtype
order by oid
}
result = ActiveRecord::Base.connection.execute(sql)
result.each do |row|
@woods
woods / enable_trim.sh
Created August 12, 2012 20:19
Enable TRIM support for 3rd Party SSDs. Works for Mountain Lion.
#!/bin/bash
#
# Enable TRIM support for 3rd Party SSDs. Works for Mountain Lion
#
# Source: http://digitaldj.net/2011/07/21/trim-enabler-for-lion/
set -e
set -x
# Back up the file we're patching
@woods
woods / .prompt.bash
Created August 25, 2012 16:25
My custom bash prompt
#!/bin/bash
#
# Scott Woods's custom bash prompt.
#
# Load this file by adding the following to the bottom of your ~/.bashrc:
#
# function prompt_command {
# export PS1=$(~/.prompt.bash)
# }
# export PROMPT_COMMAND='export LAST_RETURN_VALUE=$? ; prompt_command'
@woods
woods / clean_up_old_releases.rb
Created December 5, 2012 19:01
The script that we use to clean up old capistrano releases
#!/opt/ruby/bin/ruby
# This script will clean out old capistrano releases from a set of
# subdirectories, but will keep a minimum number. It's designed to be run as
# a cron job.
#
# (c) Copyright 2008 West Arete Computing, Inc.
require 'thread'
require 'fileutils'