Skip to content

Instantly share code, notes, and snippets.

View bradclawsie's full-sized avatar

Brad Clawsie bradclawsie

View GitHub Profile
@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))]
@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 {
@bradclawsie
bradclawsie / sharedvec.hs
Created October 9, 2012 06:11
sharedvec.hs
module Main where
import Control.Concurrent as CC
import Control.Concurrent.STM as STM
import Control.Concurrent.STM.TVar as TV
import Data.Vector as V
import GHC.Conc as GC
modifyTVar :: TVar a -> (a -> a) -> STM ()
modifyTVar tv f = readTVar tv >>= writeTVar tv . f
@bradclawsie
bradclawsie / true.go
Created August 1, 2012 06:03
make it TRUE
package main
import (
"fmt"
"encoding/json"
)
type T struct {
I int
E interface{}
@bradclawsie
bradclawsie / tmux.conf
Created July 13, 2012 06:22
tmux.conf
set-option -g status-bg black
set-option -g status-fg white
set-option -g status-interval 60
set-option -g status-left "#(/home/brad/bin/imapbiff.pl)"
set-option -g status-right "#(/home/brad/bin/temp.pl)"
set-option -g pane-active-border-fg blue
unbind %
bind | split-window -h
bind - split-window -v
bind-key k select-pane -U
#!/usr/bin/env perl
use DateTime;
$| = 1;
my $tmux_out = '';
my $sensors_bin = '/usr/bin/sensors';
if (-e -x $sensors_bin) {
my $sensors_out = `$sensors_bin`;
if ($sensors_out =~ /temp1\:\s+\+(\d+)/s) {
$tmux_out .= '|' . $1 . 'C| ';
}