Skip to content

Instantly share code, notes, and snippets.

View dbushong's full-sized avatar

David Bushong dbushong

View GitHub Profile
module Main where
import Random
import List
p=putStrLn
f(x,y)=x\\(x\\y)
e z=['*'|(p,q)<-z,p==q]++(f(unzip[x|x@(p,q)<-z,p/=q])>>"+")
n a s=getLine>>=m where{m i|i==s=return a;m i=p(e$zip i s)>>n(a+1)s}
main=mapM(\x->randomRIO('1','6'))"mind">>=n 1>>=p.("Tries: "++).show
@-moz-document url("https://www.hipchat.com/chat") {
#action_tabs .download { display: none !important; }
body.chat .tabs li a { padding-top: 4px !important; }
#action_tabs li.icon a img { top: 4px !important; }
#action_tabs { right: 1px !important; }
#header a.logo {
height: 30px !important;
width: 32px !important;
display: block !important;
overflow: hidden !important;
# i'd like this syntax to work
someFunc 42, 69,
foo: 42
bar: 79
baz: 88
"x#{x}": 92
# which would compile to something like this:
###
someFunc(42, 69, (function () {
@dbushong
dbushong / compact-campfire.user.css
Created October 12, 2013 17:51
A userstyle for Stylish for Campfire in a chromeless browser to make it fit better in small spaces
#Container > div.Left {
margin-left: -25px;
width: 87%;
}
#room_title h2#topic { font-size: 8px; }
div#Sidebar { width: 16%; }
#room_title h1#room_name { font-size: 18px; }
@dbushong
dbushong / iced.coffee
Last active January 1, 2016 11:19
Comparison of vanilla callback-passing vs. iced coffeescript vs. Q/promises. Mission is: 1. prompt for a url prefix 2. fetch (in parallel) two URLs based on that prefix 3. sleep for a number of seconds equal to the sum of the lengths of the results 4. print something announcing we're done
request = require 'request'
prompt = (str, cb) -> # same as vanilla
in = process.stdin
process.stdout.write "#{str}: "
in.setEncoding 'utf8'
in.once 'error', cb
in.once 'data', (res) ->
in.pause()
cb null, res.trim()
@dbushong
dbushong / iced.coffee
Last active January 1, 2016 11:19
Vanilla/Iced/Promise comparison for a git-exec'ing operation. Given an origin and a tag, return the SHA of the tag if it exists, else create a new tag and return that SHA
cp = require 'child_process'
git = (cmd, args, cb) -> # same as vanilla
cp.execFile 'git', [cmd].concat(args), (err, stdout) -> cb err, stdout.trim()
createTagIfMissing = (origin, tag, cb) ->
await git 'show-ref', [tag], defer err, showRef
if err?
await git 'tag', [tag], defer err
return cb err if err?
@dbushong
dbushong / stubbable.coffee
Created December 27, 2013 19:44
Mini-lib to make exported libraries more stubbable w/ e.g. bondjs
###
replace yourlib's:
module.exports = { foo, bar }
with:
module.exports = require('./stubbable') { foo, bar }
now when some file does:
{ foo } = require './yourlib'
you can still stub it with:
yourlib = require './yourlib'
bond(yourlib._fns, 'foo').return 42
@dbushong
dbushong / holdem.rb
Created October 22, 2014 00:51
old holdem implementation in ruby; used in an irc bot at one point
module TexasHoldEm
class RulesViolation < RuntimeError
end
class RingArray < Array
def [](n)
at n % size
end
end
#f '123456789',100
def f(d,t)(0...3**(d.size-1)).map{|c|d.chars.reduce{|s,g|o='+-'[c%3]||'';c=(c/3).floor;s+o+g}}.select{|e|e.scan(/\D?\d+/).map(&:to_i).reduce(:+)==t}end
if __FILE__ == $0
p f('123456789', 100)
end

Getting seconds or milliseconds since January 1, 1970, 00:00:00 GMT in various languages

Second-Native

C (1972)

// ms
struct timespec spec;
clock_gettime(CLOCK_REALTIME, &spec);