Skip to content

Instantly share code, notes, and snippets.

View oogali's full-sized avatar

Omachonu Ogali oogali

  • Ordinary Stack
  • Princeton, NJ
  • 03:47 (UTC -04:00)
View GitHub Profile
@oogali
oogali / freqsearch.rb
Created September 5, 2011 06:49
Quick FCC ULS search
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'net/http'
require 'date'
def search(freq, state)
h = Net::HTTP.new 'wireless2.fcc.gov', 80
resp, body = h.post('/UlsApp/UlsSearch/results.jsp', "fiUlsServiceSearchByType=300&ulsTowerNum=&feqSearchType=exact&fiFrequency=#{freq}&fiLowerFrequency=&fiUpperFrequency=&fiOwnerName=&fiUlsFRN=&fiCity=&ulsState=#{state.upcase}&fiUlsZipcode=&ulsCallSign=&statusAll=Y&ulsAuthTypeAll=Y&ulsDateType=&dateSearchType=+&ulsFromDate=&ulsToDate=#{Time.now.strftime('%m/%d/%Y').gsub('/', '%2F')}&fiRowsPerPage=50&ulsSortBy=uls_l_callsign++++++++++++++++&ulsOrderBy=ASC&x=42&y=10&hiddenForm=hiddenForm&jsValidated=true&searchType=ULN", { 'Referer' => 'http://wireless2.fcc.gov/UlsApp/UlsSearch/searchSite.jsp' })
@oogali
oogali / org.postgresql.postgres.plist
Created September 9, 2011 14:17
PostgreSQL launch property list
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.postgresql.postgres</string>
<key>UserName</key>
<string>postgres</string>
<key>GroupName</key>
<string>_postgres</string>
@oogali
oogali / redis-to-irc.rb
Created October 10, 2011 01:08
Redis pubsub-to-IRC bridge
#!/usr/bin/env ruby
require 'rubygems'
require 'isaac'
require 'em-hiredis'
configure do |c|
c.nick = 'redisbot'
c.server = 'irc'
c.verbose = true
@oogali
oogali / unified-diff.rb
Created October 14, 2011 19:11
Unified diff of strings in Ruby (Two nmap scans)
require 'rubygems'
require 'diff/lcs'
require 'diff/lcs/string'
require 'diff/lcs/hunk'
scan = [
%x[nmap -nsP -oG - 192.168.1.0/24].split(/\n/).map! { |e| e.chomp },
%x[nmap -nsP -oG - 192.168.1.0/24].split(/\n/).map! { |e| e.chomp }
]
@oogali
oogali / dump-har.rb
Created October 18, 2011 19:22
parse HAR files quickly
#!/usr/bin/env ruby
require 'rubygems'
require 'addressable/uri'
require 'json'
require 'yaml'
if ARGV.length != 1
puts "#{__FILE__} /path/to/archive.har"
exit 1
@oogali
oogali / nagbot.rb
Created November 22, 2011 16:04
nagios ack bot
#!/usr/bin/env ruby
# ---
# quick and dirty nagios acknowledgement bot
# [email protected]
# @oogali
# ---
#
# what do you need to run?
# - ruby 1.8+
@oogali
oogali / autocomplete.js
Created December 23, 2011 05:37
Really, really easy autocomplete with jQuery + jQuery tmpl
/*
* what's happening here?
*
* 1) define and pre-compile our template that our results should be rendered as
* 2) bind to the keydown event of the input#search text box
* 3) define our callback, to pull json search results every time we're executed
* 4) define a callback for receiving our json data, which does:
* a) remove all previous search results (<h3> tags)
* b) append our new search results to our div#results
*
@oogali
oogali / readable.rb
Created February 9, 2012 04:30
Display a duration as a readable string
require 'action_view'
include ActionView::Helpers::DateHelper
def readable(seconds)
case seconds
when 86400*3..86400*7
(Time.now - seconds).strftime('%A').downcase
when 86400*7..86400*14
'just over a week ago'
@oogali
oogali / short-and-sweet.rb
Created February 22, 2012 23:51
Short intro to Sinatra
#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
require 'haml'
get '/' do
haml :ask
end
@oogali
oogali / timeserver.rb
Created March 12, 2012 20:16
time server in ruby
#!/usr/bin/env ruby
require 'rubygems'
require 'eventmachine'
require 'time'
module TimeServer
def post_init
send_data "#{Time.now.strftime('%A, %B %e, %Y %H:%M:%S')}\n"
close_connection