Skip to content

Instantly share code, notes, and snippets.

G. D. Ritter aisamanra

Block or report user

Report or block aisamanra

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View exprtable.rs
#[derive(Debug)]
enum Expr {
Var { x: u32 },
App { f: ExprRef, arg: ExprRef },
Lam { body: ExprRef },
}
use Expr::*;
#[derive(Debug, Copy, Clone)]
@aisamanra
aisamanra / Makefile
Created May 17, 2019
C++ module example
View Makefile
CPPFLAGS = -std=c++1z -fmodules-ts
ALL: main
main: speech.o main.cc
clang++ $(CPPFLAGS) -fprebuilt-module-path=. -o $@ $^
speech.o: speech.pcm
clang++ $(CPPFLAGS) -o $@ -c $<
View Makefile
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
View match.c
#include <stdio.h>
typedef struct {
int tag;
union {
int l;
struct {
char* fst;
float snd;
} r;
@aisamanra
aisamanra / turing_morphogenesis.hs
Created Aug 19, 2016
A quick naïve Haskell implementation
View turing_morphogenesis.hs
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
View turing_morphogenesis.rs
/* 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;
View data-files-with-backpack.md

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

@aisamanra
aisamanra / simple_hans_server.hs
Created Jun 1, 2016
A basic application written using ssh-hans
View simple_hans_server.hs
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 / pratt.hs
Created Mar 11, 2016
a simple pratt parser in Haskell
View pratt.hs
{-# 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 / parser_nondet.hs
Last active Oct 16, 2015
Terrible non-deterministic parser combinators that you shouldn't use
View parser_nondet.hs
{-# 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
You can’t perform that action at this time.