Skip to content

Instantly share code, notes, and snippets.

View bradclawsie's full-sized avatar

Brad Clawsie bradclawsie

View GitHub Profile
@bradclawsie
bradclawsie / nullables.go
Created June 5, 2013 05:37
some "nullable" base types for go
type NullableString string
func (n NullableString) MarshalJSON() ([]byte, error) {
sn := string(n)
if sn == "" {
var i interface{}
return json.Marshal(i)
}
return json.Marshal(sn)
}
@bradclawsie
bradclawsie / naive_struct.go
Created June 5, 2013 05:22
naive attempt at matching json
type Foo struct {
MandatoryString string
OptionalUInt64 uint64
OptionalString string
}
;; blog.jazzychad.net/2012/08/01/array-iteration-problem.html
(use srfi-1)
(: f ((list-of number) number number -> (list-of number)))
(define f
(lambda (arr n i)
(cond [(< n 0)
;; if we are going right-to-left, reverse the list and use the abs count
(reverse (f (reverse arr) (abs n) i))]
@bradclawsie
bradclawsie / sample-run-exclusive.txt
Created March 4, 2013 07:02
how to invoke run-exclusive.sh
$ run-exclusive.sh ./testlock t.lock
@bradclawsie
bradclawsie / run-exclusive.sh
Created March 4, 2013 07:00
a wrapper to handle graceful lock breaking (when needed) of golock programs
#!/bin/zsh
# call like:
# $ run-exclusive.sh /path/of/progname /path/of/lockfile
# e.g.
# $ run-exclusive.sh ./testlock t.lock
# clearly you want progname to be something that will only match once.
# don't use a short string that is a substring match of something else running
export PROGNAME=$1
@bradclawsie
bradclawsie / testlock.go
Created March 4, 2013 06:54
a minimal program that obtains a golock lock. compile to "testlock" with go build testlock.go
package main
import (
"os"
"fmt"
"time"
"github.com/bradclawsie/golock"
)
func main() {
@bradclawsie
bradclawsie / fizzbuzz.rkt
Last active December 11, 2015 23:59
fizzbuzz in typed racket
#lang typed/racket
(define-type T (U String Integer))
(: fizzbuzz : ((Listof Integer) -> (Listof T)))
(define fizzbuzz
(lambda (l)
(cond [(null? l) '()]
[else (let* ([x (car l)]
[xs (cdr l)]
[mod3 (eq? 0 (modulo x 3))]
package main
import (
"bufio"
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
@bradclawsie
bradclawsie / http-conduits.hs
Created November 25, 2012 08:27
http-consuits.hs
module Main where
import qualified Data.Conduit as C
import qualified Network.HTTP.Conduit as HC
main :: IO ()
main = do
manager <- HC.newManager HC.def
request' <- HC.parseUrl "https://www.google.com/"
let request = request' { HC.checkStatus = \_ _ -> Nothing }
response <- C.runResourceT $ HC.httpLbs request manager
@bradclawsie
bradclawsie / fizzbuzz.rs
Created October 13, 2012 07:35
fizzbuzz.rs
extern mod std;
fn main() {
let mut i = 1;
while i <= 100 {
let mod3 = ((i % 3) == 0);
let mod5 = ((i % 5) == 0);
if ! (mod3 || mod5) {
io::println(fmt!("%d",i));
} else {