Skip to content

Instantly share code, notes, and snippets.

module _
type Vec has {
x float
y float
z float
}
fn main() {
var positions [int: Vec]
module _
# test: pass
# expect: pass with 5
# expect: pass with 6
def main()
x := 5
foo := def (y int)
print("pass with " + (x + y))
global
type OwningBuffer C has
let raw *C
let length uint
def __finalize__(owning_buffer OwningBuffer any)
posix.free(owning_buffer.raw)
@wbbradley
wbbradley / worker_queue.py
Last active January 18, 2018 03:25
A convenient pattern for spawning worker threads and a queue in Python
import logging
from contextlib import contextmanager
from Queue import Queue
from threading import Thread
class ThreadStop(Exception):
pass
@wbbradley
wbbradley / fix-the-web
Last active January 11, 2018 16:45
Make this a bookmark in your Chrome.
javascript:if (1) {
var node = document.createElement('style');
node.innerHTML = "body { font-family: Georgia; width: 35em; line-height:1.5; margin-left: auto; margin-right: auto; } p { margin-top: 1em; }";
document.head.appendChild(node);
}
@wbbradley
wbbradley / tee.zion
Last active December 30, 2017 04:26
start of simple tee implementation
module tee
get sys
get file
def main()
if len(sys.args) == 2
newline := "\n"
f := file.open(sys.args[1], "w")
state := f.state
@wbbradley
wbbradley / 1. condition_refinement.zion
Last active December 4, 2017 14:58
Zion: Refining Types in Short-circuited Logical Expressions
module _
def gimme_bool() bool
return true
def main()
static_print(7)
static_print("hello")
static_print(gimme_bool())
static_print(gimme_bool() ? "foo" : 4.5)
@wbbradley
wbbradley / fix-private-hostname.sh
Last active May 16, 2017 20:08
put the private ip into /etc/hosts
# Run this after your AMI comes online
private_hostname=ip-$(curl http://169.254.169.254/latest/meta-data/local-ipv4 2>/dev/null | sed s/\\./-/g)
sudo su - -c "grep $private_hostname /etc/hosts || echo 127.0.0.1 $private_hostname >> /etc/hosts"
module _
# test: pass
type C{T} is
Ax(T, int, float) or
Bx(int, T, float) or
Cx(int, float, T)
def main()
a_int := Ax(4, 5, 2.1)
@wbbradley
wbbradley / types.py
Last active June 2, 2016 16:01
Typed lambda calculus implementation
#!/usr/bin/python
# coding=utf8
"""
Lambda Calculus with Unification for Algebraic Data Types with Macros.
Copyright (c) 2016 William Bradley
The MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to