Skip to content

Instantly share code, notes, and snippets.

@Capncavedan
Capncavedan / gist:983025
Created May 20, 2011 14:32
Rider combinations for Theft Guard bonds
@http://www.pivotaltracker.com/story/show/9610041
Feature: agent orders theft guard bond
As an agent I should be able to order a theft guard bond
with only valid rider combinations
Background:
Given the fidelity bond templates
Given I'm an authenticated agent belonging to an agency
When I go to the Theft Guard products page
@Capncavedan
Capncavedan / gist:1872044
Created February 20, 2012 22:45
Useful additions to Enumerable
module Enumerable
def to_histogram
result = Hash.new(0)
each { |x| result[x] += 1 }
result
end
def most_popular
h = self.to_histogram
max_by { |x| h[x] }
@Capncavedan
Capncavedan / gist:1876924
Created February 21, 2012 14:52
Installing MySQL 2.8.1 gem
env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
@Capncavedan
Capncavedan / gist:1932894
Created February 28, 2012 14:41
How to create a set of ImageRight diary items
# UPDATED May 16 2012 for ImageRight v5
# How to generate a set of diary items for agencies
# Use rails console, paste list of agency ids into %w below
# Adjust other parameters as appropriate
# IMPORTANT: left pad with zeros to make agency ids 5 digits
agency_ids = %w( ).map{|a| a.to_s.rjust(5, '0')}.uniq.sort
diary_items = []
@Capncavedan
Capncavedan / gist:2151003
Created March 21, 2012 18:40
closed / open logic from ye olde DOMINO systeme
CLOSED LOGIC:
longExpDate :=
@Middle(@Text(BDEXP);4;2) + "/" +
@Middle(@Text(BDEXP);6;2) + "/" +
@Left(@Text(BDEXP);4);
declinedOrCompletedStatReport := @If(progressStatus = "Closed" : "Completed" : "Declined";1;0);
cond1 := @TextToNumber(@Text(BDBAMT)) < 100000 & !BDDEL = "" : "P" & @Right(BIIC;1) = "Y";
@Capncavedan
Capncavedan / gist:2170952
Created March 23, 2012 14:06
Output set of numbers as ranges
# courtesy of http://codepad.org/tBON208e
$_ = "1,2,3,8,9,12,15,17,18,19,20,21,22,23";
s/(?<!\d)(\d+)(?:,((??{$++1})))+(?!\d)/$1-$+/g;
print;
@Capncavedan
Capncavedan / gist:2223007
Created March 28, 2012 02:29
Ruby Date and Time symbol meanings
# Date and Time symbol meanings:
%a - The abbreviated weekday name (``Sun'')
%A - The full weekday name (``Sunday'')
%b - The abbreviated month name (``Jan'')
%B - The full month name (``January'')
%c - The preferred local date and time representation
%d - Day of the month (01..31)
%H - Hour of the day, 24-hour clock (00..23)
%I - Hour of the day, 12-hour clock (01..12)
@Capncavedan
Capncavedan / gist:2293043
Created April 3, 2012 15:45
how to install rdiscount 1.6.8 with jruby 1.6.7
Bundler command complained of not being able to find bundle1.o although I could easily locate it within /usr/lib myself.
Damn computers.
gem install rdiscount -- --with-ldflags="-L/usr/lib"
@Capncavedan
Capncavedan / Ruby script
Created April 9, 2012 15:45
Ruby script to show OS X battery info at command line
#!/usr/bin/ruby
ioreg_data = IO.popen("ioreg -w0 -l").readlines().join
ioreg_data.sub!(/.*(\+\-o AppleSmartBattery.*?\+\-o).*/m, '\\1')
ioreg_data.gsub!(/\s+\|/, "")
ioreg_data.gsub!(/\s\s+/, "\n")
battery = Hash.new
ioreg_data.split(/\n+/).each do |line|
key, value = line.split(' = ')[0..1]
next if key.nil? || value.nil?
Contract Bond Factory
FactoryGirl.build(:contract_bond)
--> Principal
--> Appointed Agency
--> contract_underwriter
--> User
--> Domino User
--> Assistant