This file contains hidden or 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
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') |
This file contains hidden or 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
require 'nokogiri' | |
require 'open-uri' | |
require 'date' | |
require "awesome_print" | |
def clean_whitespace(a) | |
a.gsub(/[\r\n\t]/, ' ').squeeze(" ").strip | |
end |
This file contains hidden or 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
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] |
This file contains hidden or 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
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 |
This file contains hidden or 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
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] |
This file contains hidden or 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
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 |
This file contains hidden or 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
require 'net/http' | |
url = URI.parse('http://localhost:7001/AppName') | |
class Producer | |
def initialize(thread_id) | |
@write_count = 0 | |
@thread_id = thread_id | |
end |
This file contains hidden or 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
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 |
This file contains hidden or 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
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" |
This file contains hidden or 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
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' } |