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
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 |
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 '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 |
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
module BlockTEA | |
# | |
# encrypt: Use Corrected Block TEA to encrypt plaintext using password | |
# Return encrypted text as 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
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 |
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
--- 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 |
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
# 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 |
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 get_word | |
@word = gets.chomp | |
@word | |
end | |
words = [] | |
while get_word != '' | |
words << @word | |
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
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 " |
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
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) | |
} |