Skip to content

Instantly share code, notes, and snippets.

@o-sam-o
o-sam-o / Act-As-Dag Graph
Created January 31, 2011 01:56
Use GraphViz to construct a diagram of a Rails act as dag relation
desc 'Uses graphviz to construct a graph of SuperCategories'
task :super_category_graph => :environment do
File.open('super_categories.dot', 'w') do |f|
f.puts "digraph super_categories {\n"
SuperCategory.all.each do |super_category|
super_category.children.each do |child|
f.puts %{"#{super_category.name}" -> "#{child.name}";\n}
end
end
f.puts '}'
@o-sam-o
o-sam-o / Check Cookie Cucumber Step
Created February 9, 2011 23:12
Cucumber step for testing if a cookie is set correctly
@o-sam-o
o-sam-o / Shell Commands Cheetsheet
Created March 19, 2011 02:05
Cheatsheet for shell commands that i want to remember
# Setup dir so changes to a ruby version and gemset on entry
rvm --rvmrc --create <ruby>@<gemset>
# Backup a mysql database
mysqldump -u [username] -p [databasename] > [backupfile.sql]
# Stop mac from sleeping
pmset noidle
# Strip quotes around digits in VIM
@o-sam-o
o-sam-o / .vimrc.local
Created March 19, 2011 07:08
My VIM settings used with Janus
" Disable toolbar
if has("gui_running")
set guioptions=egmrt
endif
color rootwater
set guifont=Monaco:h12
set spell
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' }
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"
@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
@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: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 / 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]