Skip to content

Instantly share code, notes, and snippets.

View bradclawsie's full-sized avatar

Brad Clawsie bradclawsie

View GitHub Profile
@bradclawsie
bradclawsie / correct.go
Last active January 26, 2017 03:27
curious correct Go program
package main
import (
"fmt"
"time"
)
func main() {
c := make(chan struct{},1)
go func() {
@bradclawsie
bradclawsie / panic.go
Created September 12, 2016 04:06
panic.go
package main
import (
"errors"
"log"
)
func final() {
log.Printf("cleaning up")
if c := recover(); c != nil {
@bradclawsie
bradclawsie / httpdshutdown_example.go
Created January 31, 2016 22:05
httpdshutdown_example.go
package main
import (
"log"
"net"
"net/http"
"github.com/bradclawsie/httpdshutdown"
"os"
"os/signal"
"time"
)
@bradclawsie
bradclawsie / gp.pl
Last active October 6, 2015 17:54
gp.pl
#!/usr/bin/perl
use Cwd;
use Env;
use File::Copy;
use v5.20;
my $argc = scalar @ARGV;
die "use gp.pl basepath reponame" unless ($argc == 2);
my $base = $ARGV[0];
my $repo = $ARGV[1];
@bradclawsie
bradclawsie / numberpuzzle.hs
Created July 12, 2015 04:21
number puzzle
module Main where
import Prelude as P
import Control.Monad as M
import Data.Text as T
import Data.Text.Read as TR
import Data.Either as E
import Data.List as L
import Data.Maybe as MB
-- http://programmingpraxis.com/2015/06/26/find-the-missing-number/
package main
import (
"bufio"
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
@bradclawsie
bradclawsie / putjson.go
Created February 26, 2015 23:42
putjson.go
package main
import (
"fmt"
"os"
"time"
"net/http"
"encoding/json"
"github.com/smugmug/godynamo/conf"
@bradclawsie
bradclawsie / ss.c
Created October 31, 2014 05:12
ss.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int ss(char *n, char *h) {
const size_t n_len = strlen(n);
// empty needle is in haystack
if (n_len == 0) return 1;
const size_t h_len = strlen(h);
// needle cannot be longer than haystack
@bradclawsie
bradclawsie / ss
Created March 19, 2014 04:38
substring
substring a b = ss a b
where
ss (x:xs) (y:ys) = if (x == y) then ss xs ys else substring a ys
ss (x:xs) _ = False
ss _ _ = True
@bradclawsie
bradclawsie / bst
Created March 19, 2014 04:38
balanced search tree
data Tree = Empty | Node Tree Int Tree deriving (Show)
insert n Empty = Node Empty n Empty
insert n (Node l i r) = if n <= i then Node (insert n l) i r else Node l i (insert n r)