Skip to content

Instantly share code, notes, and snippets.

@flagranterror
flagranterror / pad.rb
Created February 15, 2012 22:00
Quick and lazy RRDTool padding
#!/usr/bin/env ruby
# pad an RRD with 5-minute data covering 24 hours
# starting yesterday
time = Time.now.to_i - 86400
288.times do
time = time + 300
puts "rrdtool update test.rrd #{time}:#{rand(1..64)}"
@flagranterror
flagranterror / gist:1847524
Created February 16, 2012 20:15
Send selected story to Reading List
--Grab selected story pertinents
tell application "NetNewsWire"
set u to (URL of selectedHeadline)
set t to (title of selectedHeadline)
end tell
--Hand off to Safari
tell application "Safari"
add reading list item (u as string)
end tell
@flagranterror
flagranterror / uploader.rb
Created February 21, 2012 15:34
Sinatra basic file uploader
#!/usr/bin/env ruby
require 'sinatra'
require 'haml'
get "/upload" do
haml :upload
end
post "/upload" do
@flagranterror
flagranterror / gist:1901707
Created February 24, 2012 15:53
Open Safari URL in IE in Parallels
property theUrl : ""
tell application "Safari"
set theUrl to URL of current tab of window 1
end tell
set validUrl to text ((offset of ":" in theUrl) + 1) thru -1 of theUrl
tell application "Internet Explorer"
@flagranterror
flagranterror / gist:1903980
Created February 24, 2012 21:48
Open Current Safari Window in Chrome
property theURL : ""
tell application "Safari"
set theURL to URL of current tab of window 1
end tell
tell application "Google Chrome"
@flagranterror
flagranterror / gist:1994207
Created March 7, 2012 16:29
Split dhcpd.leases into a md array of declarations
#!/usr/bin/env ruby
@leases =[]
File.open('dhcpd.leases', 'r').read.gsub(/\n/, '').split('}').each { |lease| @leases << lease.split(';') }
@flagranterror
flagranterror / lease_parser.rb
Created March 28, 2012 14:47
ISC DHCPD lease parsing
def cache_leases
leases = {}
File.open('/path/to/dhcpd.leases', 'r').read.gsub(/\n/, '').split(/}/).each do |lease|
l = lease.split(';')
if l.index(' next binding state free')
l[0].gsub!(/.*lease (.*?) {.*/, '\1')
leases[l[0]] = l if l[0] =~ /[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/
end
@flagranterror
flagranterror / gist:3106160
Created July 13, 2012 17:32
Populate /etc/issue with interface IPs
#!/bin/bash
cp /etc/issue-clean /etc/issue
for x in $(ip link show | egrep -o 'eth[0-9]')
do
INTERFACE=$x
for y in $(ip addr show ${INTERFACE} | grep -o 'inet .*' | awk '{ printf "%s|%s\n", $7, $2 }')
do
@flagranterror
flagranterror / clamcolor.sh
Created July 28, 2012 23:42
Color files in finder based on clamscan results.
#!/bin/sh
clamscan="/usr/local/bin/clamscan"
file=$1
if [ -z "$clamscan" ]
then
echo "Add clamav to your \$PATH or set \$clamscan, dawg."
exit 1
@flagranterror
flagranterror / gist:3340701
Created August 13, 2012 13:22
Tcpdump output parsing
#!/usr/bin/env ruby
f = File.open("tcpdump.log", 'r')
endpoints = {}
conversations = {}
f.each_line do |l|