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.
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
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 = [] |
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 '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 |
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
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" |
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
# 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 |
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
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 |
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
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> |
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
#!/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 |
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 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 |
OlderNewer