Skip to content

Instantly share code, notes, and snippets.

View stuart's full-sized avatar

Stuart Coyle stuart

  • Brisbane, Australia
View GitHub Profile
!#/usr/env ruby
require 'json'
require 'uri'
# Removes repeated messages from one of the AMQP queues.
#
# USAGE: ruby queue_uniq.rb "queue_name"
#
# This will dump the whole queue to a temp file. (In case anything goes wrong)
# it will strip out any messages with the duplicated payloads then
@stuart
stuart / queue_fix.rb
Last active December 19, 2015 22:19
!#/usr/env ruby
require 'json'
require 'uri'
# Removes repeated USER records from one of the AMQP queues.
#
# USAGE: ruby queue_fix.rb queue_name, email_address
#
# This will dump the whole queue to a temp file. (In case anything goes wrong)
# it will strip out the user messages containing the email provided then
@stuart
stuart / geolocatable.rb
Created October 13, 2011 03:12
Acts as geolocatable
module Geolocatable
def acts_as_geolocatable(options = {})
options = {:lat => 'lat', :lng => 'lng'}.merge(options)
write_inheritable_attribute :acts_as_geolocatable_options, options
class_inheritable_reader :acts_as_geolocatable_options, options
include Geolocatable::Model
@stuart
stuart / ABNCheck.rb
Created February 14, 2011 06:20
Check a string to see if it is a valid Australian Business Number
# Algorithm taken from ATO website.
def valid_abn?(abn)
WEIGHTS = [10,1,3,5,7,9,11,13,15,17,19]
tmpabn = abn.split("").map{|c| c.to_i}
tmpabn[0] = tmpabn[0] - 1
checksum = (0..10).inject(0) do |sum, i|
sum + (tmpabn[i].to_i * WEIGHTS[i])
end
return (checksum % 89) == 0
end