Skip to content

Instantly share code, notes, and snippets.

Note to Self

Be Confident

Tests build confidence. Write 'em. They'll save your ass, and they'll let you take a chainsaw to your code without being afraid of unintended consequences.

Be Lazy

def fill_in_the_gaps(date_array,value_array,num_of_values)
#out of 2 arrays, one
date_value_array = []
date_array.length.times do
date_value_array << [[Time.parse(date_array.pop.to_s).strftime("%Y-%m-%d")],[value_array.pop]]
end
# fill in the gaps with zeros
val_index = 0
dates = []
require 'DBI'
require 'mysql'
#This class is for interacting with databases. :) Handles Mysql and SQL Server.
class Database
attr_reader :db_type, :connection_string
attr_accessor :cnnxn
def initialize(conn_string,opts={})
options={:db_type => 'sql_server'}.merge(opts)
@connection_string = conn_string
@csexton
csexton / gist:181448
Created September 5, 2009 15:55 — forked from mdarby/gist:181192
before "deploy", "deploy:check_revision"
namespace :deploy do
desc "Make sure there is something to deploy"
task :check_revision, :roles => [:web] do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts ""
puts " \033[1;33m**************************************************\033[0m"
puts " \033[1;33m* WARNING: HEAD is not the same as origin/master *\033[0m"
puts " \033[1;33m**************************************************\033[0m"
@csexton
csexton / env.rb
Created September 12, 2009 03:52 — forked from tpope/env.rb
# Enable Webrat's Selenium mode if one or more scenarios is tagged @selenium
Webrat.configure do |config|
config.mode = :rails
ObjectSpace.each_object(Cucumber::Ast::Features) do |features|
config.mode = :selenium if features.tag_count('selenium').nonzero?
end
end
params = {'server[ip_address]' => localhost.ip_address, 'server[hostname]' => localhost.hostname,
'server[param_1]' => localhost.registry_user_base_dir, 'server[default_gateway]' => localhost.default_gateway,
'server[param_2]' => localhost.registry_sql_connect, 'server[netmask]' => localhost.netmask, 'server[route_table]' =>
route_table, 'server[os]' => localhost.os, 'server[build_date]' => localhost.build_date, 'server[service_pack]' =>
localhost.service_pack, 'server[subnet]' => localhost.subnet, 'server[persistent_route_table]' => persistent_route_table}
#old way
#x = Net::HTTP.post_form(URI.parse('http://report1.atbackup.local/servers/create'),params)
#new way
xml = <<-eos
<?xml version="1.0" encoding="UTF-8"?>
<server>
<build-date type="datetime" nil="true"></build-date>
<created-at type="datetime" nil="true"></created-at>
<default-gateway>10.60.1.4</default-gateway>
<hostname>XML Test</hostname>
<ip-address>0.0.0.0</ip-address>
<netmask>255.255.0.0</netmask>
<os>FuzzyOS</os>
@csexton
csexton / rlsp.rb
Created November 9, 2009 04:10 — forked from h0rs3r4dish/rlsp.rb
#!/usr/bin/ruby
RLSP_VERSION = "1.4.1"
class Lambda
attr_accessor :args, :body
def initialize(args=[],body="")
@args = (args.class == Array) ? args : [args]
@body = body
end
class Canine
VERSION = '1.3'
def initialize(&block)
@commands = Hash.new
@default = @latest = :commands
@empty = nil
@auto = {
:commands => hash_command("commands","Show a list of commands",Proc.new {
@commands.each { |cmd| c = cmd[1]
name = c[:name].to_s
@csexton
csexton / menu.mm
Created December 17, 2009 15:52 — forked from atr000/menu.mm
- (void)installButtonBeforeItem:(NSString *)beforeItem toToolbar:(NSString *)toolbarIdentifier
{
log_enter();
NSToolbar *toolbar = nil;
for (NSWindow *window in [NSApp orderedWindows]) {
if (NO == [[[window toolbar] identifier] isEqualToString:toolbarIdentifier]) continue;
toolbar = [window toolbar];
if ([toolbar respondsToSelector:@selector(onepasswordSetDelegate:)]) {
[toolbar setDelegate:[toolbar delegate]]; // this will call a swizzled method