Skip to content

Instantly share code, notes, and snippets.

View chessai's full-sized avatar

chessai chessai

View GitHub Profile
@chessai
chessai / Main.hs
Created December 12, 2018 18:05
Averaged across persons, excluding legal fees, how much money had each person spent by time 6?
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Main (main) where
import Colonnade (Headed)
import Data.ByteString (ByteString)
import Data.Map (Map)
import Data.Text (Text)
import Siphon (Siphon, SiphonError)
@chessai
chessai / bash.bash
Last active December 10, 2018 16:48
example of setting up a nixos service on a non-nixos machine
# a simple service, 'mysql'
$ cat example.nix
{ pkgs, ... }:
{
services.mysql.enable = true;
services.mysql.package = pkgs.mysql;
}
# build the service
http://www.eas.uccs.edu/~mwickert/ece5655/lecture_notes/ece5655_chap10.pdf
@chessai
chessai / dmap_aeson_orphan.hs
Created November 30, 2018 20:21
aeson instances for dmap
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
{-# OPTIONS_GHC -Wall -Werror -fno-warn-orphans #-}
module Data.Dependent.Map.JSON () where
import Data.Aeson (ToJSON(..),FromJSON(..))
import Data.Exists (Exists(..),ToJSONKeyForall(..),
ToJSONKeyFunctionForall(..),ToJSONForall(..),ToSing(..),
@chessai
chessai / cpp_hell.hs
Last active December 17, 2019 14:07
{-# LANGUAGE CPP #-}
#define InnieOuttie IO
#define class module
#define begin where
#define mayo main
#define memo putStrLn
gm (middle of line)
% (match of next brace, bracket, comment, #define)
{ stdenv, fetchFromGitHub, pkgconfig, vpnc, openssl ? null, gnutls ? null, gmp, libxml2, stoken, zlib } :
assert (openssl != null) == (gnutls == null);
let
version = "7.08";
name = "openconnect_pa-${version}";
in stdenv.mkDerivation {
inherit name;
newtype Branch (o :: OS) e m a = Branch (ExceptT e m a)
deriving
( Applicative, Eq, Foldable, Functor, Monad, Traversable
)
branchToExceptT :: Branch o e m a -> ExceptT e m a
branchToExceptT = coerce
mkArg :: Int -> String
mkArg n = "arg" ++ show n
mkDegenerate :: Int -> Int -> String
mkDegenerate start end = "f " ++ (mconcat $ intersperse "@" $ map mkArg [start..end]) ++ " = " ++ mkArg end
@chessai
chessai / cool.hs
Last active November 13, 2018 21:13
import Data.Functor.Compose
doubleFmap :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b)
doubleFmap = fmap . fmap
fooMonad :: (Monad f, Functor g) => f (a -> b) -> f (g a) -> f (g b)
fooMonad fab fga = fab >>= \f -> doubleFmap f fga
fooApplicative :: (Applicative f, Applicative g) => f (a -> b) -> f (g a) -> f (g b)
fooApplicative fab fga = getCompose (Compose (fmap pure fab) <*> Compose fga)