Skip to content

Instantly share code, notes, and snippets.

@mattyw
mattyw / stack.idr
Created May 12, 2017 23:06
stack calc
module Main
import Data.Vect
data StackOp : Type -> Nat -> Nat -> Type where
Push : Integer -> StackOp () height (S height)
Pop : StackOp Integer (S height) height
Top : StackOp Integer (S height) (S height) -- this means there has to be at least one item on the stack
GetStr : StackOp String height height
PutStr : String -> StackOp () height height
@mattyw
mattyw / cheapbootstrap
Created February 1, 2017 12:53
cheap juju bootstrap, now in haskell \o/
#!/usr/bin/env runhaskell
{-# LANGUAGE OverloadedStrings #-}
import System.Environment
import System.Process
import System.Exit
usage = putStrLn "need to specify cloud and controller name"
@mattyw
mattyw / Even.idr
Created November 17, 2016 21:00
Something wrong with my dependent types
data Even = E Nat
data Odd = O Nat
data Num = Ev Nat | Od Nat
NumType : Num -> Type
NumType (Ev k) = Even
NumType (Od k) = Odd
mkEven : Nat -> Num
let random_object = System.Random()
let filelines filename = System.IO.File.ReadAllLines(__SOURCE_DIRECTORY__ + "/" + filename)
let get_random_line file = random_object.Next(0, Seq.length(file))
let get_random_word word_file = Seq.nth (get_random_line word_file) (word_file)
type words =
| Verb
| Noun
| Adjective
@mattyw
mattyw / show_cookies.py
Created May 17, 2016 09:46 — forked from cmars/show_cookies.py
Show ~/.go-cookies content without compromising authorization tokens
#!/usr/bin/env python3
import base64
import json
import os
import sys
if __name__ == '__main__':
if sys.argv[1:]:
filename = sys.argv[1]
@mattyw
mattyw / gocover
Last active January 7, 2016 11:09
A useful script to put in your path
#!/bin/sh
file=`mktemp`
echo $file
go test -coverprofile=$file $@
go tool cover -html=$file
@mattyw
mattyw / panic.log
Created February 3, 2015 06:01
go version devel +1757b5c Thu Dec 11 07:31:32 2014 +0000 linux/amd64
runtime: g24: leftover defer argp=0xdeaddeaddeaddead pc=0x4872ea
defer 0xc2081d1d40 argp=0xdeaddeaddeaddead pc=0x4872ea
defer 0xc2081d1d00 argp=0xdeaddeaddeaddead pc=0x8f488c
defer 0xc208296040 argp=0xdeaddeaddeaddead pc=0xb3c28e
fatal error: traceback has leftover defers
runtime stack:
runtime.gothrow(0x14aeef0, 0x1d)
/home/mattyw/go/src/runtime/panic.go:507 +0x98
runtime.gentraceback(0x42e348, 0xc208193c20, 0x0, 0xc2080e79e0, 0x0, 0x0, 0x7fffffff, 0x16a0af0, 0x0, 0x0, ...)
// Sleep sort
// http://archives.cazzaserver.com/SleepSortWiki/SleepSort.html
package main
import (
"fmt"
"time"
)
func sorter(c chan int, value int) {
@mattyw
mattyw / get-in.go
Created August 28, 2013 20:58
A go equivalent of clojure's get-in function. Query a nested map with a list of keys
package main
import (
"fmt"
)
func getIn(i interface{}, keys []string) interface{} {
if len(keys) == 0 {
return i
}
@mattyw
mattyw / spawn.exs
Created June 17, 2013 21:13
When I run this code I get: =ERROR REPORT==== 17-Jun-2013::22:09:20 === Too many processes ** (SystemLimitError) a system limit has been reached :erlang.spawn(Main, :thread, [#PID<0.2.0>])
import :timer, only: [sleep: 1]
defmodule Main do
@num 1000000
def thread(pid) do
:timer.sleep(10000)
pid <- {:result, 1}
end
def collector(x) when x == @num do