Skip to content

Instantly share code, notes, and snippets.

View supernullset's full-sized avatar

Sean Williamson supernullset

View GitHub Profile
@supernullset
supernullset / Bieberlicious
Created August 24, 2012 00:35
Wrapper to connect to my riak instance
{-# LANGUAGE DeriveGeneric, OverloadedStrings #-}
import Network.Riak
import Network.Riak.Connection as C
import Network.Socket as S
import System.IO.Unsafe (unsafePerformIO)
import Data.ByteString.Lazy.Char8 as BSL
import Network.Riak.JSON.Resolvable as RR
import Network.Riak.Types
import Data.Aeson
@supernullset
supernullset / probe.rb
Created September 6, 2012 05:38
Weird net/ftp behavior
require 'net/ftp'
ftp_root = "tgftp.nws.noaa.gov"
# Im running conn_test with arbitrary values for n
def conn_test(root, n)
(1..n).to_a.each do |i|
ftp = Net::FTP.new root
begin
ftp.passive
@supernullset
supernullset / levenshtein_ranking.coffee
Created October 17, 2012 19:13
Fuzzy string comparison/sort in javascript
curry = (fn)->
slice = Array.prototype.slice
args = slice.apply arguments, [1]
return ->
fn.apply null, args.concat(slice.apply arguments)
levenshteinD = (s,t) ->
if !s.length then return t.length
if !t.length then return s.length
@supernullset
supernullset / test.rb
Created October 31, 2012 21:36
minitest integration
require "minitest_helper"
describe "Root path acceptance test" do
before do
@company1 = create(:awesome_sauce_llc, featured: true)
@company2 = create(:better_than_you_inc, featured: true)
end
describe "when not logged in" do
before { visit root_path }
@supernullset
supernullset / null.coffee
Created November 5, 2012 03:56
Example of WIP-Menu for supernullset.com
w = 1000
h = 500
X = d3.scale.ordinal().domain([90]).rangePoints([0,w],1)
Y = d3.scale.ordinal().domain([180]).rangePoints([0,h],2)
upper_arc = d3.svg.arc()
.innerRadius(95)
.outerRadius(105)
.startAngle(0)
.endAngle(Math.PI)
require "sugar"
dust = require "dust"
redis = require "redis"
client = redis.createClient()
clicker = (app) ->
client.get "clicker", (e,cr) ->
client.get "timed", (e,tr) ->
app.render index: {clicker: cr, timed: tr}
@supernullset
supernullset / method_chaining_helper.rb
Created December 11, 2012 04:26
Method chaining by message sending
class Object
def send_each(*methods)
methods.inject(self) do |o, m|
o.respond_to?(m) ? o.public_send(m) : o
end
end
end
class MethodSequence
def document_download_cells(object, name, icon_path)
@supernullset
supernullset / gist:4271872
Created December 12, 2012 21:40
redirect_test
def create
# generic file specific code
if files = params.fetch(:flu_vaccine){{}}.fetch(:generic_files){nil}
@file_uploads = GenericFile.new files if files.fetch(:name) != ""
end
params.fetch(:flu_vaccine){{}}.delete :generic_files
# vaccine specific code
@vaccine = FluVaccine.new(params.fetch(:flu_vaccine){{}})
@supernullset
supernullset / BadDOM.coffee
Created December 21, 2012 20:33
Worst Abuse Ever
seat_index = "seat-#{arc_index}"
if href = SEATS[seat_index]["link"]
if !@links then @links = exports ? this
if !@links.hash then @links.hash = {}
@links.hash[seat_index] = href
d3.select(".#{seat_index}").on "click", ->
seat_index = this.classList[1]
href = window.links.hash[seat_index]
window.open href, "_blank"
@supernullset
supernullset / monsterAttack.rs
Created January 6, 2013 14:59
MonsterAttack
use core::rand::{Rng};
struct Monster {
name: ~str,
health: HealthPoints,
mut speed: int,
mut charisma: int,
mut max_attack: int,
position: Position