Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / hindley-milner.php
Created September 18, 2014 17:53
A Hindley-Milner type system in PHP
<?php
/** Lambda abstraction */
class Lambda
{
function __construct($v, $body) {
$this->v = $v;
$this->body = $body;
}
module Main
%default total
data Rational = MkRational Nat Nat
numerator : Rational -> Nat
numerator (MkRational n d) = n
@gbluma
gbluma / divide_by_zero.idr
Created May 9, 2014 21:08
A simple example showing how divide by zero can be restricted in Idris
module Main
%default total
myDivide : Nat -> (y:Nat) -> so (y /= 0) -> Nat
myDivide x y p = div x y
main : IO ()
main =
print (show (myDivide 3 1 oh)) -- compiles successfully
@gbluma
gbluma / .bashrc
Created January 27, 2014 15:52
Recording keystroke count in Linux
function keystroke-record() {
sudo cat /dev/input/event5 >> /tmp/keyboard.log &
}
function keystroke-count() {
echo $( echo "$( cat /tmp/keyboard.log | wc -c ) / 96" | bc -l )
}
function keystroke-reset() {
sudo cat /dev/null > /tmp/keyboard.log
@gbluma
gbluma / deploy.sh
Last active January 4, 2016 01:39
A deploy script that can look at old versions of code in Git
#!/bin/bash
function deploy() {
echo "Deploying tag: $1"
# create a working folder
mkdir -p "$DEPLOY_DIR/$1"
# dump code to this new folder
git archive $(cat .git/refs/tags/$1):src 2>/dev/null | \
@gbluma
gbluma / Readme.md
Last active April 17, 2022 18:11
Writing tool that inserts newlines after every prepositional phrase.

I like to use a technique from Richard Lanham's book "Revising Prose" to help myself write better English sentences. In the book, Lanham suggests that we break apart sentences at each predicate. Doing this helps us visually see the structure of our words. Errors and issues with flow stand out immediately. Likewise, sentences that contain many predicates don't flow nicely.

Splitting these sentences manually is a bit of work. Fortunately a computer can do this work trivially. It is not a problem to repetitively split apart sentences based on simple rules. Below is a program I

@gbluma
gbluma / security-types.rkt
Created December 9, 2013 16:29
Security types in Racket
#lang typed/racket
;; Types ---------------------------------
(struct: (a) High ([v : a])) ; a wrapper for high security objects
(struct: (a) Low ([v : a])) ; a wrapper for low security objects
(define-type (ST a) (U (High a) (Low a))) ; a type that can be used for either high or low
;; allows us to get the value of the object regardless of the type (reduces duplication)
(: ST-v (All (A) ((ST A) -> A)))
(define (ST-v a)
@gbluma
gbluma / fb.c
Created November 5, 2013 22:02
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
// application entry point
int main(int argc, char* argv[])