Skip to content

Instantly share code, notes, and snippets.

module Main
%default total
data Rational = MkRational Nat Nat
numerator : Rational -> Nat
numerator (MkRational n d) = n
@gbluma
gbluma / ssh_config
Last active August 29, 2015 14:07
A script to listen for local file changes and push them to a remote server
# The contents of this file go in ~/.ssh/config
ControlMaster auto
ControlPath ~/.ssh/sockets/%h_%p_%r
ControlPersist yes
TCPKeepAlive yes
# try to keep connections open for four hours (adjust as you see fit)
ServerAliveInterval 4
ServerAliveCountMax 1
@gbluma
gbluma / security.scala
Last active August 29, 2015 14:07
A minimal security monad that allows low-security and high-security elements to be mixed, but in all places where the values are mixed, the output adopts the highest-security tag. This is useful in situations where sensitive data pervades many computational contexts and where the security rules are bipolar (strictly public/private, etc.)
/**
* A minimal security monad that allows low-security and high-security elements
* to be mixed, but in all places where the values are mixed, the output
* adopts the highest-security tag. This is useful in situations where
* sensitive data pervades many computational contexts and where the security
* rules are bipolar (strictly public/private, etc.)
*
* @author Garrett Bluma
* @date Apr 9, 2012 (Monad design and implementation)
* @revised Oct 2, 2014 (Cleaned up. Added examples)
@gbluma
gbluma / DictionaryParser.flx
Created November 28, 2014 20:00
Felix Dictionary parser
class DictionaryParser {
requires package "re2";
open Regdef;
struct KeyValue {
key : string;
value : string;
}
float n() {
return random(50);
}
float[] soften(float[] curve) {
for (int i=0; i<19;i++){
curve[i] = curve[i] + (curve[i]-curve[i+1])/5;
}
for (int i=19; i>0; i--){
curve[i] = curve[i] + (curve[i-1]-curve[i])/5;
#lang racket
(require 2htdp/batch-io) ; provides read-csv-file
(require srfi/1) ; provides reduce function
(require plot) ; provides plot function
;; helper functions
(define (sum xs) (reduce + 0 xs))
(define (square x) (* x x))
// TODO: support more than just linux/osx
include "std/posix/filesystem";
// TODO: add this to std/io/textio.flx, it's missing
gen fopen_append : string -> ofile = '::std::fopen($1.c_str(), "a")';
object Repl () = {
# Use something easier to type as the prefix.
set -g prefix C-f
unbind C-b
bind C-f send-prefix
# Relax!
set -sg escape-time 0
set -sg repeat-time 600
# This is hilariously absurd. How many nerds use tmux on OS X every day and
@gbluma
gbluma / object-algebra.flx
Last active August 29, 2015 14:23 — forked from anonymous/gist:65c37929d31fa0fceb21
An example of Object Algebras in Felix
// Title: An example of Object Algebras in Felix
// Author: Garrett Bluma
// Date: June 29, 2015
// Special thanks to Bruno Oliveira and William Cook for explaining object
// algebras, and for providing examples.
// <http://i.cs.hku.hk/~bruno/oa/>
// -----------------------------------------
// Object algebras use extension via type parameters and inheritance. Given a
class CT
{
class Semigroup[T,U] {
virtual fun \circ : T * T -> T;
}
class Monoid[T,U] {
inherit Semigroup[T,U];
virtual fun id : () -> T;