Skip to content

Instantly share code, notes, and snippets.

@aisamanra
aisamanra / gidl-mode.el
Created April 9, 2015 00:21
Major mode for editing GIDL files
;; a simple major mode for editing GIDL files.
(setq gidl-font-lock
'(( "def-\\(enum\\|struct\\|newtype\\|interface\\)"
. font-lock-keyword-face )
( "def-\\(enum\\|struct\\|newtype\\|interface\\) (?\\([A-Za-z0-9_-]*\\)"
2 font-lock-function-name-face )
( "[us]int\\(8\\|16\\|32\\|64\\)_t\\|bool_t\\|float_t\\|double_t"
. font-lock-builtin-face)))
@aisamanra
aisamanra / gidl.vim
Created May 7, 2015 22:19
unfinished gidl mode for vim
" Vim syntax file
" Language: GIDL
" Last Change: 2014 April 17
" Maintainer: Getty Ritter <gdritter@galois.com>
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
@aisamanra
aisamanra / parser_nondet.hs
Last active October 16, 2015 20:34
Terrible non-deterministic parser combinators that you shouldn't use
{-# LANGUAGE ParallelListComp #-}
import Data.Char (isDigit)
import Data.List (nub)
import Data.Monoid ((<>))
parse :: Eq a => Parser tk a -> [tk] -> Maybe [a]
parse p tk = case runParser p tk of
[] -> Nothing
xs -> Just $ nub $ map snd xs
@aisamanra
aisamanra / pratt.hs
Created March 11, 2016 22:22
a simple pratt parser in Haskell
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as M
import MonadLib
type Tables t a = (PrefixMap t a, InfixMap t a)
newtype PrattM t r a = PrattM
{ runPrattM :: ReaderT (Tables t r) (StateT [t] (ExceptionT String Id)) a
@aisamanra
aisamanra / simple_hans_server.hs
Created June 1, 2016 06:09
A basic application written using ssh-hans
module Main where
{-
Here is a real---if not particularly interesting---interaction with this server:
[gdritter@armilla ~]$ ssh -p 9999 localhost incr
ok.
[gdritter@armilla ~]$ ssh -p 9999 localhost incr
ok.
[gdritter@armilla ~]$ ssh -p 9999 localhost double

There'd be a standard signature somewhere, which I will call Dist.DataFiles, and it'd look like this

module Dist.DataFiles(getDataFileName) where
  getDataFileName :: FilePath -> IO FilePath

This would have a handful of basic, built-in implementations, including the often-standard

/* This is a naive implementation of Jonathan McCabe's elaboration of
* Alan Turing's model of morphogenesis, as described here:
* http://www.jonathanmccabe.com/Cyclic_Symmetric_Multi-Scale_Turing_Patterns.pdf
*/
extern crate rand;
use rand::Rng;
use std::env;
use std::io::Write;
@aisamanra
aisamanra / turing_morphogenesis.hs
Created August 19, 2016 18:43
A quick naïve Haskell implementation
import Control.Monad (forM_)
import Data.Array
import Data.Ix
import System.Random (randomIO)
-- A 'Size' is just a pair of Ints
type Pair = (Int, Int)
-- An 'Image' is a packed, pair-indexed array
type Image a = Array Pair a
#include <stdio.h>
typedef struct {
int tag;
union {
int l;
struct {
char* fst;
float snd;
} r;
main: libsample.a
gcc -lpthread -ldl main.c libsample.a -o main
libsample.a: sample.rs
rustc --crate-type=staticlib sample.rs
clean:
rm -f main libsample.a