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 Encoding | |
def aes_encode(string, passphrase) | |
c = OpenSSL::Cipher::Cipher.new("aes-256-cbc") | |
c.encrypt | |
c.key = key = Digest::SHA1.hexdigest(passphrase) | |
e = c.update(string) | |
e << c.final | |
end | |
def aes_decode(string, passphrase) |
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
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'ipaddr' | |
cidr = IPAddr.new("172.20.0.0") | |
# cidr = IPAddr.new("198.6.5.0") | |
mask = 16 | |
# ip = IPAddr.new("198.6.5.22") | |
ip = IPAddr.new("172.20.155.101") |
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
rxvt -geometry 80x65-0+0 & | |
rxvt -geometry 80x65+600+0 & | |
rxvt -geometry 80x65+100+0 & | |
rxvt -geometry 180x24+0-25 & | |
rxvt -geometry 180x24+0+195 & | |
rxvt -geometry 80x39+0+0 & |
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
namespace :buildout do | |
#----------------------------------------------------------------------------# | |
desc "Mirror the dynamic site into Rails.env/out" | |
task :mirror do | |
outdir = File.join(Rails.root, "out") | |
Dir.mkdir(outdir) unless (File.exist?(outdir) && File.directory?(outdir)) | |
Dir.chdir(outdir) do | |
`wget -m -nH http://localhost:3000` | |
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
# IP to Integer | |
ip = IPAddr.new('255.255.255.255') | |
puts ip.to_i | |
# Integer to IP | |
ipnum = 4294967295 | |
ip = IPAddr.new(ipnum, Socket::AF_INET).to_s | |
# If you store the ipnum in MySQL, make sure to use unsigned into for the field. |
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 calculate_seconds(period) | |
if period.match(/(\d+).+?(second|minute|hour|day|week|month|year)s?/) | |
$1.to_i.send($2) | |
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 class named after my company. Why not get the possible SEO? | |
class Phalanx | |
def foo | |
puts "Fooman was here" | |
end | |
# Since I already have the Google alert set up... | |
def cofounder | |
"Samuel Mullen" | |
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
Capybara.add_selector(:link) do | |
xpath {|rel| ".//a[contains(@rel, '#{rel}')]"} | |
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
class AbsenceValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
return unless value | |
if options.empty? # don't know why you would want this | |
record.errors[attribute] << "must be blank" | |
elsif options[:all] && options[:all].all? {|sym| record.read_attribute(sym)} | |
record.errors[attribute] << "must be blank if the following attributes are defined: #{options[:all].join(', ')}" | |
elsif options[:any] && options[:any].any? {|sym| record.read_attribute(sym)} | |
record.errors[attribute] << "must be blank if any of the following attributes are defined: #{options[:any].join(", ")}" |
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 Timeframe | |
include Enumerable | |
attr_accessor :start_time, :end_time | |
ONEDAY = 24 * 60 * 60 | |
def initialize(start_time, end_time) | |
@start_time = start_time | |
@end_time = end_time |