Skip to content

Instantly share code, notes, and snippets.

View samullen's full-sized avatar

Samuel Mullen samullen

View GitHub Profile
@samullen
samullen / ip2int.rb
Created October 11, 2010 20:44
IP to Integer and back
# 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.
@samullen
samullen / buildout.rake
Created September 29, 2010 13:05
Rails to Static site generation and deployment
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
@samullen
samullen / setup.sh
Created September 27, 2010 23:57
setting up my preferred terminal workspace layout
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 &
@samullen
samullen / cidr_validation.rb
Created August 20, 2010 19:37
Testing IP's against CIDR. Whitelisting blocks.
#!/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")
@samullen
samullen / encoding.rb
Created August 19, 2010 18:39
Dumbed down module to show eas encoding/decoding
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)
@samullen
samullen / mp.js
Created August 1, 2010 13:56
mp.js
if (!RegExp(/^\s*$/).test($("#message-popdown").html())) {
$("#message-popdown").slideDown("slow", function() {
var that = $(this);
setTimeout(function() {that.slideUp();}, 5000);
});
}
$("#message-popdown").click(function() {
$(this).slideUp();
});
@samullen
samullen / mp.css
Created August 1, 2010 13:56
mp.css
#message-popdown {
background-color: #dea852;
display: none;
position: fixed;
z-index: 999;
cursor: pointer;
padding-top: 20px;
padding-bottom: 20px;
-webkit-border-bottom-right-radius: 10px;
-webkit-border-bottom-left-radius: 10px;
@samullen
samullen / mp.html
Created August 1, 2010 13:55
mp.html
<div id="message-popdown" class="grid_12">
<% if flash[:error_msg] %>
<span class="error-msg"><%= flash[:error_msg] %></span>
<% elsif flash[:success_msg] %>
<span class="success-msg"><%= flash[:success_msg] %></span>
<% elsif flash[:warning_msg] %>
<span class="warning-msg"><%= flash[:warning_msg] %></span>
<% elsif flash[:message] %>
<span class="notice-msg"><%= flash[:message] %></span>
<% end %>
@samullen
samullen / last_day_of_month.rb
Created April 30, 2010 14:01
find the last day of the month
require 'date'
(Date.new(year, 12, 31) << (12-month)).day # Ruby 1.8.x
Date.new(2010, 12, 31).prev_month(12 - 4).day # Ruby 1.9.x
# requires and stuff go here
def load_irbrc(path)
return if (path == ENV["HOME"]) || (path == '/')
load_irbrc(File.dirname path)
irbrc = File.join(path, ".irbrc")
load irbrc if File.exists?(irbrc)