This file contains hidden or 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
#!/usr/bin/env ruby -wKU | |
B64_ALPHABET = ('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a + ['+', '/'] | |
class Integer | |
def to_s64( base = 64 ) | |
input = self | |
out = "" | |
while input > 0 | |
digit = input % base |
This file contains hidden or 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 'openssl' | |
require 'base64' | |
require 'stringio' | |
plaintext = StringIO.new <<-EOF | |
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | |
Also, because I said so. | |
EOF | |
target_key = OpenSSL::PKey::RSA.new(640) |
This file contains hidden or 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 'openssl' | |
def simple_decrypt(iv,crypted,password) | |
crypt = OpenSSL::Cipher::Cipher.new("aes-256-cbc") | |
crypt.decrypt | |
crypt.key = Digest::SHA256.digest(password) | |
crypt.iv = iv | |
data = crypt.update(crypted) | |
data << crypt.final rescue nil | |
end |
This file contains hidden or 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
SetEnv !needs_ct | |
SetEnvIf Request_Method POST needs_ct | |
SetEnvIf Content-Type "\S+" !needs_ct | |
RequestHeader set Content-Type "application/x-www-form-urlencoded" env=needs_ct |
This file contains hidden or 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
# Approximates the chance of at least one collision in a random | |
# distribution of k items across n possible IDs. Adapted from | |
# Karsten's approximate calculator at http://tinyurl.com/5zt6ol | |
def collision_probability( k, n ) | |
1 - Math.exp((-k ** 2) / ( 2.0 * n).to_f) | |
end | |
# The odds of two people having the same birthday are slightly | |
# greater than 50% if you have 23 or more people. | |
puts collision_probability( 23, 365 ) # => 0.515509538061517 |
This file contains hidden or 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
// Finds unused indexes in a mysql database | |
SELECT | |
t.TABLE_SCHEMA, | |
t.TABLE_NAME, | |
s.INDEX_NAME, | |
s.COLUMN_NAME, | |
s.SEQ_IN_INDEX, | |
( SELECT MAX(SEQ_IN_INDEX) | |
FROM INFORMATION_SCHEMA.STATISTICS s2 |
This file contains hidden or 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
# HACK !!! This forces a post-hoc "preload" | |
Product.send(:preload_associations, p, 'product_type') |
This file contains hidden or 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
#!/usr/bin/env ruby | |
ENV["RAILS_ENV"] = (ENV['RAILS_ENV'] || "development").dup | |
require File.dirname(__FILE__) + '/../config/boot' | |
require RAILS_ROOT + '/config/environment' | |
MAX_AGE = 4.weeks | |
def archive(tablename, finder_sql) | |
raise ArgumentError if tablename.blank? or finder_sql.blank? | |
start_time = Time.now.to_f |
This file contains hidden or 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
#!/bin/sh | |
# | |
# Settings from Evan Weaver | |
# http://blog.evanweaver.com/articles/2009/04/09/ruby-gc-tuning/ | |
# | |
RUBY_HEAP_MIN_SLOTS=500000 | |
RUBY_HEAP_SLOTS_INCREMENT=250000 | |
RUBY_HEAP_SLOTS_GROWTH_FACTOR=1 | |
RUBY_GC_MALLOC_LIMIT=50000000 |
OlderNewer