Skip to content

Instantly share code, notes, and snippets.

View wishdev's full-sized avatar

John W Higgins wishdev

  • Battle Ground, WA
View GitHub Profile
@wishdev
wishdev / gist:635f7a839877d79a6781
Created July 24, 2014 02:50
Recursive grouping and bucket assignment
with
-- Shamelessly stolen from
-- http://www.postgresql.org/docs/9.3/static/queries-with.html
recursive groups (key1, key2, path, cycle)
AS (
select key1,
key2,
ARRAY[ROW(key1, key2)],
false
from graph
@wishdev
wishdev / cookie_array.rb
Created April 6, 2011 17:13
Monkey Patching cookie_array
require 'pqueue'
pq = PQueue.new proc{|x, y| x.compare(y)}
#Do either the Array monkey_patch or Record concept
class Array
attr_reader :insert_time
def compare(other_record)
#We want to return TRUE if this record should take
module BlockTEA
#
# encrypt: Use Corrected Block TEA to encrypt plaintext using password
# Return encrypted text as string
class Array
def spread(members)
ret = Array.new
dist = count.to_f/(members-1)
(members-1).times{ |pos|
ret << at((pos*dist).floor)
}
ret << at(-1)
end
end
--- ruby.eselect-20090723 2009-07-23 19:02:39.000000000 -0700
+++ /usr/share/eselect/modules/ruby.eselect 2009-08-01 23:34:39.814660501 -0700
@@ -12,7 +12,7 @@
find_targets() {
for t in ${ROOT}${bindir}/${1:-ruby}{18,19,1.9,2.0,ee} ; do
- [[ -e $t ]] || continue
+ [[ -e $t && ! -h $t ]] || continue
echo ${t}
done
@wishdev
wishdev / gist:146751
Created July 14, 2009 06:17
Ruby and GMail
# http://www.jamesbritt.com/2007/12/18/sending-mail-through-gmail-with-ruby-s-net-smtp
# http://d.hatena.ne.jp/zorio/20060416
require "openssl"
require "net/smtp"
Net::SMTP.class_eval do
private
def do_start(helodomain, user, secret, authtype)
raise IOError, 'SMTP session already started' if @started
def get_word
@word = gets.chomp
@word
end
words = []
while get_word != ''
words << @word
end
require 'pp' #lets make things look pretty shall we
days=5
dataset=[25.0000,24.8750,24.7813,24.5938,24.5000,24.6250,25.2188,27.2500,26.2500,26.5938]
weighted_avgs = []
#lets break the data down to "days" size blocks - we'll only do calculations on full sets
dataset.each_cons(days) { |block|
puts "Working with "
@wishdev
wishdev / gist:131578
Created June 17, 2009 23:12
Weighted Average
days = 5
data = [ 25.0000, 24.8750, 24.7813, 24.5938, 24.5000, 24.6250, 25.2188, 27.2500, 26.2500, 26.5938 ]
avg_data = Array.new(data.length) { |pos|
tot = 0
# we check to see if we have enough days left to do a full average - otherwise use whatever we have left
day_count = days + pos < data.length ? days : data.length - pos
day_count.times { |day|
tot += data[pos + day] * (day_count - day)
}