Skip to content

Instantly share code, notes, and snippets.

View boj's full-sized avatar

Brian Jones boj

  • Eagle River, Alaska
View GitHub Profile
@boj
boj / Main.hs
Created December 15, 2017 23:02
ExceptT Example
#! /usr/bin/env nix-shell
#! nix-shell -i 'runghc -XLambdaCase' -p 'ghc.withPackages (pkgs: [ pkgs.mtl ])'
module Main where
import Control.Monad.Except (ExceptT, runExceptT, throwError)
f :: (Monad m, Num n, Fractional n, Eq n) => n -> n -> ExceptT String m n
f a b
| a == 0 = throwError "Divide by zero"
with import <nixpkgs> { };
stdenv.mkDerivation rec {
name = "kakoune-unstable-${version}";
version = "2017-12-03";
src = fetchFromGitHub {
repo = "kakoune";
owner = "mawww";
rev = "7d32b3fc3689219d47fc236eefa4749f2e7c3c61";
sha256 = "1xdfmz1gd84s4svk1hffnxam6clhgm37w64rr3mfimvmvxhnzzcc";
@boj
boj / kakrc
Created January 13, 2018 14:02
.config/kak/kakrc
#colorscheme dracula
set-option global ui_options ncurses_assistant=cat
set global tabstop 2
set global indentwidth 2
# replace ¥ with \
hook global InsertChar ¥ %{ exec -draft -itersel <esc>hr\\i }
@boj
boj / dracula.kak
Created January 13, 2018 14:03
.config/kak/colors
# dracula theme
# https://draculatheme.com/
%sh{
black="rgb:282a36"
gray="rgb:44475a"
white="rgb:f8f8f2"
pink="rgb:ff79c6"
purple="rgb:bd93f9"
@boj
boj / Random.hs
Created April 18, 2018 03:51
Haskell System.Random
module Main where
-- https://hackage.haskell.org/package/random-1.1/docs/System-Random.html
import System.Random
import Data.Int
import Data.List (splitAt)
main :: IO ()
main = do
@boj
boj / TaskManager.hs
Created June 30, 2018 04:47
A Haskell task manager using Async which handles proper thread shutdown
module TaskManager
( mkTaskManager
, runTasks
, execTask
, waitTasks
, cancelTasks
) where
--------------------------------------------------------------------------------
import Control.Concurrent
@boj
boj / Stacks.hs
Last active September 8, 2018 05:39
module Main where
import Control.Concurrent (forkIO, threadDelay)
import Control.Monad (forever)
import Control.Monad.State (StateT, execStateT, get, put)
import Data.Foldable (traverse_)
import Debug.Trace
data AppState
= AppState
@boj
boj / App.hs
Created October 18, 2018 10:26
Haskell freer-simple example
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
module App where
@boj
boj / Main.hs
Created October 25, 2018 07:32
Haskell Partial Application Example
module Main where
f :: Int -> String -> String
f n a = mconcat . take n . repeat $ a
g :: String -> String -> String
g a b = b <> " " <> a
z :: (String -> String) -> String
z f = f "world"
@boj
boj / Main.hs
Created October 25, 2018 07:32
Haskell Partial Application Example
module Main where
f :: Int -> String -> String
f n a = mconcat . take n . repeat $ a
g :: String -> String -> String
g a b = b <> " " <> a
z :: (String -> String) -> String
z f = f "world"