Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
typedef struct {
int tag;
union {
int l;
struct {
char* fst;
float snd;
} r;
@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
@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

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

module Main where
import Data.List (nub)
import MonadLib
import UI.TCOD.Console
import UI.TCOD.Console.Types
import UI.TCOD.Color
type Pt = (Int, Int)
type St = (Pt, [Pt])
@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
;; guile-utf8.scm
;; A quickly hacked together set of functions to turn
;; utf-8-encoded text (which Guile sees as raw bytes) into
;; ASCII-encoded HTML, with a few other functions for
;; getting the code values out of a UTF-8 string.
;; anon-let is a hacky macro to create a new scope while
;; allowing definitions within it to bind in its enclosing
;; scope. It also allows define-local which only defines
;; within that scope. It is used here to close over constants
@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 / 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 / ghc-wrapper.sh
Created March 27, 2015 21:05
wrapper script for switching between and installing different GHC versions
#!/bin/bash -e
# ghc wrapper script (for managing installed GHC versions)
# this is a small script I use that allows multiple simultaneous ghc
# installations. This makes the following assumptions about how
# you want to set up your system:
# - GHC version {X} is installed with prefix ~/install/ghc-${X}
# - A file naming the current selected GHC version is placed
# at ~/.current-ghc
# - cabal is configured to point to this script instead of ghc