Skip to content

Instantly share code, notes, and snippets.

@rwjblue
rwjblue / priv_pub_test.rb
Created April 25, 2012 20:26
Standalone PrivatePub publishing...
require 'private_pub'
PrivatePub.load_config('config/private_pub.yml','development')
PrivatePub.publish_to('/faye_images/index/JONJ',{})
@rwjblue
rwjblue / print_folder_tk.rb
Created June 26, 2012 18:09 — forked from pwelch/print_folder_tk.rb
Ruby/Tk script with GUI to print a folder using a system call to lp (CUPS). (Requires cups gem)
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/tile'
require 'tkextlib/bwidget'
require 'cups'
$dirname = TkVariable.new
root = TkRoot.new {title "Print Folder"}
@rwjblue
rwjblue / copy_images_from_tracker.rb
Created August 18, 2012 01:14
Copy missing receipt images back to PMNAS02
require 'csv'
require 'pry'
require 'mysql2'
require 'fileutils'
class TrackerCopy
PMNAS_PATH = '/media/pmnas02'
ORB_RUNNER_PROCESSED_PATH = '/home/public/processed'
@rwjblue
rwjblue / geokit_test.rb
Created August 18, 2012 17:12
Use Geokit to validate State and/or Zipcode
require 'geokit'
geo = GeoKit::Geocoders::MultiGeocoder.multi_geocoder('34471')
if geo.success
geo.state # => FL
geo.city # => Ocala
geo.country # => US
end
geo = GeoKit::Geocoders::MultiGeocoder.multi_geocoder('Ocala, FL')
@rwjblue
rwjblue / hour_intervals_from_times.rb
Created August 25, 2012 01:22 — forked from rondale-sc/hour_intervals_from_times.rb
Calculate percentage of interval covered within a given hour.
def hour_intervals(start_time, stop_time)
results = Hash.new {|h,k| h[k] = Hash.new(0)}
(start_time.to_i..stop_time.to_i).step(60).collect do |minute|
minute_time = Time.at(minute)
interval = case minute_time.min
when (0..14) then 0
when (15..29) then 15
when (30..44) then 30
when (45..59) then 45
@rwjblue
rwjblue / format_currency.rb
Created September 5, 2012 19:15
format_currency Method
def format_currency(input, options = {:currency_symbol => '$', :delimiter => ',', :separator => '.', :precision => 2})
input ||= 0
number = "%01.#{options[:precision]}f" % input.to_d.round(options[:precision]).to_s("F")
parts = number.to_s.to_str.split('.')
parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{options[:delimiter]}")
options[:currency_symbol] + parts.join(options[:separator])
end
@rwjblue
rwjblue / cellify.rb
Created September 7, 2012 05:15
Use cellify method to allow overridable defaults per cell in Prawn.
require 'prawn'
def cellify(data, default_options = nil)
default_options ||= {:borders => []}
output = []
row_options = default_options.delete(:rows) || Hash.new {|h,k| h[k] = {}}
column_options = default_options.delete(:columns) || Hash.new {|h,k| h[k] = {}}
current_row = -1
data.each do |row|
@rwjblue
rwjblue / rename_route.rb
Created September 12, 2012 21:34
Rename a current route, and update all path helpers to the new name.
#! /usr/bin/env ruby
require 'pathname'
old_controller_name = ARGV[0]
new_controller_name = ARGV[1]
old_routes = `rake routes | grep #{old_controller_name}`.split("\n").map{|str| str.strip.split.first}.uniq.compact - ['GET','PUT','POST','DELETE','root']
routes_file_contents = File.read('config/routes.rb')
File.open('config/routes.rb', 'w'){|io| io.write routes_file_contents.gsub(":#{old_controller_name}", ":#{new_controller_name}") }
@rwjblue
rwjblue / barcode_to_eps.rb
Created September 21, 2012 21:18
Generate barcode to EPS with ruby (barby).
require 'barby'
require 'barby/barcode/code_39'
require 'barby/outputter/cairo_outputter'
File.open('pp_002.eps', 'w'){|io| io.write Barby::Code39.new('PP 002').to_eps}
@rwjblue
rwjblue / list.sh
Created September 26, 2012 21:52
List account and distribution list details in Zimbra
sudo su - zimbra
# list all accounts and print out account name and aliases
for i in `zmprov -l gaa` ; do zmprov ga $i zimbraMailAlias ; done
# list all distribution lists and any members and/or aliases
for i in `zmprov gadl` ; do zmprov gdl $i zimbraMailAlias zimbraMailForwardingAddress ; done