Skip to content

Instantly share code, notes, and snippets.

View capoferro's full-sized avatar

Josiah Kiehl capoferro

View GitHub Profile
@capoferro
capoferro / user.rb
Created November 12, 2010 15:57
AES decryption for Authlogic
def decrypted_password
aes.decrypt
aes.key = Rails.configuration.aes256_key
password = aes.update(self.crypted_password.unpack("m").first)
(password << aes.final).gsub(%r(#{self.password_salt}$), '')
end
private
@capoferro
capoferro / user.rb
Created November 12, 2010 16:02
Straight AES encrypt/decrypt
def encrypt_bugdb_password
if !(self.bugdb_password_changed? or self.new_record?)
return
end
cipher = OpenSSL::Cipher::Cipher.new CipherHelper::encryption_type
cipher.encrypt
cipher.key = Digest::SHA1.hexdigest CipherHelper::key
cipher.iv = self.initialization_vector = cipher.random_iv
encrypted_password = cipher.update self.bugdb_password
encrypted_password << cipher.final
@capoferro
capoferro / gist:748072
Created December 20, 2010 05:52
I like writing unit tests
(test/with-test
(defn to_wound
([s t]
(let [x (+ 4 (- t s))]
(max 2 (min 6 x)))))
(test/is (= (to_wound 3 3) 4))
(test/is (= (to_wound 3 4) 5))
(test/is (= (to_wound 3 2) 3))
(test/is (= (to_wound 3 1) 2))
(test/is (= (to_wound 4 1) 2))
@capoferro
capoferro / config
Created January 2, 2011 15:43
ssh config
Host *yourdomain.com
User someuser
@capoferro
capoferro / term
Created January 2, 2011 15:45
test the pubkey
$ ssh yourdomain.com
group :development do
rake-remote_task
end
@capoferro
capoferro / Rakefile
Created January 2, 2011 15:48
Simple task
require 'rake/remote_task'
host 'yourdomain.com', :app
remote_task :example_task, role: :app do
run 'uname -a'
end
@capoferro
capoferro / term
Created January 2, 2011 15:49
Expected Output
$ rake example_task
(in /home/josiah/Projects/gem-testers)
Linux gem-testers.org 2.6.32.16-linode28 #1 SMP Sun Jul 25 21:32:42 UTC 2010 i686 Intel(R) Xeon(R) CPU L5520 @ 2.27GHz GenuineIntel GNU/Linux
(test/with-test
(defn- swap-duel-probabilities
([probabilities]
{:lead (:follow probabilities) :follow (:lead probabilities)}))
(test/is (= (swap-duel-probabilities {:lead 0.5 :follow 0.6}) {:lead 0.6 :follow 0.5})))
(defn aggregate-probability
([probabilities duelist]
(reduce
@capoferro
capoferro / piano.rb
Created February 3, 2011 05:18
Automatically log into pandora with pianobar.
#! /usr/lib/ruby
require 'open3'
Open3.popen2('pianobar', 'r+') do |stdin, stdout|
out = ''
sleep_now = false
loop do
o, i, _ = IO.select([stdout], [stdin], nil, 10000000)
unless o.first.nil?
out += o.first.readpartial(8000)