Skip to content

Instantly share code, notes, and snippets.

View jamesthompson's full-sized avatar

James Thompson jamesthompson

View GitHub Profile
@jamesthompson
jamesthompson / Pubsub.hs
Created December 1, 2020 16:03
Example pub/sub grpc interface with fused-effects
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE KindSignatures #-}
@jamesthompson
jamesthompson / keybase.md
Created February 15, 2017 20:22
keybase proof

Keybase proof

I hereby claim:

  • I am jamesthompson on github.
  • I am james_rth (https://keybase.io/james_rth) on keybase.
  • I have a public key ASDoRfTsm8xenyyW3WnK2OabszUxiN4gGDNit_NJtwfUsgo

To claim this, I am signing this object:

@jamesthompson
jamesthompson / install-stack-raspbian.sh
Created February 1, 2017 16:46
A script to install stack on Raspbian
#!/bin/sh
set +ex
# A script to install stack on Raspbian
# Use stack installer script to install stack
curl -sSL https://get.haskellstack.org/ | sh
# Use apt-get to install llvm
@jamesthompson
jamesthompson / GenericGogolDatastore.hs
Last active August 31, 2016 11:37
Gogol Datastore Generic Record Serializer
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
@jamesthompson
jamesthompson / Triangle2.hs
Created August 30, 2016 12:42
Triangle string with alternating 0 and 1 characters
import Data.List (intersperse)
import Data.Monoid (mconcat)
triangleIO :: IO ()
triangleIO = putStrLn triangle
triangle :: String
triangle = mconcat . intersperse "\n" . fmap (intersperse ' ') $ cycle ['0']
where cycle x = x : (cycle x >>= growOne)
growOne (x:z) = [opp x:x:z]
@jamesthompson
jamesthompson / Triangle.hs
Last active August 29, 2016 20:18
Triangle 0 1 printing with comonadic stream
import Control.Comonad (extract, (<<=), (=>>))
import Control.Monad (void)
import Data.Functor (fmap)
import Data.List (intersperse)
import Data.List.NonEmpty (NonEmpty, toList, (<|))
import Data.Monoid (mconcat)
import Data.Traversable (traverse)
import Prelude (IO, Int, String, drop, id, mod, otherwise,
putStrLn, take, undefined, ($), (.), (==))
@jamesthompson
jamesthompson / demoapp
Last active August 12, 2016 18:31
demoapp
{
"name": "DemoApp",
"preferences": [
{
"categories": [
{
"example": "guardian-stevebell: New opinion from Steve Bell at the Guardian",
"id": "news",
"matches": [
"guardian-stevebell: (.*)"
@jamesthompson
jamesthompson / TrentTree.hs
Created September 6, 2015 16:19
Dir Tree Prog
module TrentTree where
import Control.Monad.Trans.Class -- from the `transformers` package
import Control.Monad.Trans.Except -- from the `errors` package
import Data.Monoid ((<>))
import Data.Tree
import System.Directory (doesDirectoryExist,
getDirectoryContents)
import System.FilePath (combine, takeFileName)
{
defaults =
{ config, pkgs, ... }:
{ deployment.targetEnv = "virtualbox";
deployment.virtualbox.memorySize = 2048; # Mb
deployment.virtualbox.headless = true;
};
}
@jamesthompson
jamesthompson / machines.nix
Created May 1, 2015 19:06
machine network def
{ numZookeeperNodes ? 1 }:
with import <nixpkgs/lib>;
let
makeMachine = n: nameValuePair "zk-${toString n}"
({ config, pkgs, nodes, ... }: