Skip to content

Instantly share code, notes, and snippets.

@gbluma
gbluma / input.haxe
Created November 1, 2013 16:23
Statically checked Option types in PHP? Finally.
import php.Lib;
import php.Web;
enum Option<T> {
None;
Some( item: T );
}
class Index {
@gbluma
gbluma / sync.sh
Created October 4, 2013 20:32
inotify-tools auto upload script
#!/bin/bash
# wait for any modification events, then do an action when they come up
inotifywait -mqre close_write -e delete --format "%:e %w %f" ./ | while read -r event path newfile
do
# don't upload temporary files
if [[ $newfile =~ .*~|\.swp.* ]]; then
continue
fi
@gbluma
gbluma / gist:6831535
Last active December 24, 2015 16:59
clean up old docker images (those without names)
for x in $(sudo docker images | grep none | awk '{print $3}'); do sudo docker rmi $x; done
sudo docker ps -a | awk '{print $1}' | xargs sudo docker rm
@gbluma
gbluma / test.hs
Created October 3, 2013 06:23
Exhaustiveness checking in Haskell
-- test.hs ---------------------------------------
module Main where
data Foo = F1 | F2 | F3 deriving (Show, Eq)
foo :: Foo -> Foo
foo x = case x of
F1 -> F2
F2 -> F3
F3 -> F1
@gbluma
gbluma / vimrc
Last active March 5, 2019 21:58
vimrc
:syntax on
"Syntax Support
au BufRead,BufNewFile *.md set syntax=tex
:autocmd FileType * set formatoptions=tcql nocindent comments&
:autocmd FileType c,cpp set formatoptions=croql cindent comments=sr:/*,mb:*,ex:*/,://
au FileType htm,html,xhtml,xml so ~/.vim/ftplugin/html_autoclosetag.vim
au BufRead,BufNewFile *.fs,*.fsx set filetype=fs
au BufRead,BufNewFile *.fs,*.fsx set syntax=ocaml
au! BufRead,BufNewFile *.gsl setfiletype gsl
@gbluma
gbluma / exhaustive.rkt
Created September 29, 2013 13:45
Exhaustive pattern matching (refinement types!) in Typed/Racket.
#lang typed/racket
;; We get exhaustive pattern matching
(: f ((U String Integer) -> Boolean))
(define (f x)
(cond
[(string? x) (string=? x "hi")] ; covers string needs
[(exact-nonnegative-integer? x) (= x 7)] ; covers positive integers
[(even? x) (= x -8)] ; we can actually cover a subset of negative integers
@gbluma
gbluma / typedEnums.php
Created September 23, 2013 22:11
Type inhabited enumerations and type-directed pattern matching
<?php
class Matcher {
private $cases = array();
function __construct($target, $source) {
$this->target = $target;
$this->source = $source;
}
@gbluma
gbluma / scan.py
Created June 12, 2013 19:16
A simple fuzzy string scanner
import zlib, os, sys
def getsize(s):
return len(zlib.compress(s))
def dist(a, b):
n1 = getsize(a); n2=getsize(b)
return (min(getsize(a+b), getsize(b+a)) - min(n1,n2))/float(max(n1,n2))
@gbluma
gbluma / primes.acl2
Last active December 17, 2015 16:39
Some cross-language testing I've done lately. Benchmarks are not accurate because the algorithm is not consistent enough.
(defun inner (k n)
(cond
((> (* k k) n) 1)
((= 0 (mod n k)) 0)
(t (inner (+ k 2) n))))
(defun is_prime (n)
(cond
((= n 2) 1)
((< n 2) 0)
@gbluma
gbluma / complex-newton.wxm
Created May 12, 2013 23:37
Newton's method for finding fixpoints in complex plane
good_enough(f, guess) :=
if (cabs(f(guess))<1E-15) then true
else false$
improve(f, guess) :=
guess - (f(guess)/(at (diff (f(z), z, 1), [z = guess])))$
newton(f,guess) :=
if (good_enough(f,guess)=true)
then guess