Skip to content

Instantly share code, notes, and snippets.

@o-sam-o
o-sam-o / gist:1207966
Created September 10, 2011 05:21
Hobart City Council Development Applications
require 'nokogiri'
require 'open-uri'
require 'date'
require "awesome_print"
url = "http://www.hobartcity.com.au/go/AdvertisedApps/output.html"
doc = Nokogiri::HTML(open(url))
table = doc.at_css('table')
@o-sam-o
o-sam-o / gist:1207916
Created September 10, 2011 04:23
Scrap Mackay City Council Development Applications
require 'nokogiri'
require 'open-uri'
require 'date'
require "awesome_print"
def clean_whitespace(a)
a.gsub(/[\r\n\t]/, ' ').squeeze(" ").strip
end
@o-sam-o
o-sam-o / gist:1180613
Created August 30, 2011 10:25
Haskell Compile Question
import Control.Monad
-- Compiles
loadPaths :: FilePath -> IO [Int]
loadPaths filename = do strings <- liftM lines $ readFile filename
return (map read strings)
-- Doesn't Compile
loadPaths :: FilePath -> IO [Int]
@o-sam-o
o-sam-o / gist:1117966
Created August 1, 2011 11:20
Hacky Attempt At Haskell Reverse Polish Notation
solveRPN :: String -> Double
solveRPN [] = 0
solveRPN s = head $ foldl solveRPN' [] $ words s
solveRPN' :: [Double] -> String -> [Double]
solveRPN' (x2:x1:stack) "+" = (x1 + x2):stack
solveRPN' (x2:x1:stack) "-" = (x1 - x2):stack
solveRPN' (x2:x1:stack) "*" = (x1 * x2):stack
solveRPN' stack num = (read num):stack
@o-sam-o
o-sam-o / QuickSort.hs
Created July 17, 2011 02:18
Haskell QuickSort
myQS :: (Ord a) => [a] -> [a]
myQS [] = []
myQS (x:xs) = myQS lessThanPivot ++ [x] ++ myQS greaterThanEqualToPivot
where lessThanPivot = [l | l <- xs, l < x]
greaterThanEqualToPivot = [l | l <- xs, l >= x]
@o-sam-o
o-sam-o / gist:1073350
Created July 9, 2011 05:22
Haskell Hack
import Data.Char
import Data.Maybe
import Data.List
import Data.Map hiding (map)
import Text.Printf
main = do
src <- readFile "grades.txt"
let pairs = map (split.words) (lines src)
let grades = foldr insert empty pairs
@o-sam-o
o-sam-o / gist:1005945
Created June 3, 2011 06:11
Hacky script that sloooowly posts data to a web app
require 'net/http'
url = URI.parse('http://localhost:7001/AppName')
class Producer
def initialize(thread_id)
@write_count = 0
@thread_id = thread_id
end
@o-sam-o
o-sam-o / gist:978031
Created May 18, 2011 05:14
Remove duplicate lines in a text file
list = []
File.open("list.txt", "r") do |infile|
while (line = infile.gets)
list << line.strip
end
end
list.uniq.each do |l|
p l
end
enable :inline_templates
get '/:username' do |username|
pass if username.blank?
resp = Net::HTTP.get_response(URI.parse("http://api.forrst.com/api/v2/users/posts?username=#{username}"))
data = resp.body
result = JSON.parse(data).with_indifferent_access
pass if result[:stat] == 'fail'
response['Cache-Control'] = "public, max-age=3600"
require 'rubygems'
require 'nokogiri'
require 'sqlite3'
require 'highline/import'
# Login to Forrst if we haven't already done so
unless File.exists?('f-cookie')
email = ask("Email Address or Username?")
password = ask("Password?") { |q| q.echo = 'x' }