Skip to content

Instantly share code, notes, and snippets.

View coot's full-sized avatar
:octocat:

Marcin Szamotulski coot

:octocat:
View GitHub Profile
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE DerivingStrategies #-}
@coot
coot / Synchronisation.hs
Last active May 13, 2021 21:06
LastToFinshSTM without `Semigroup` constraint.
module Synchronisation where
import Control.Concurrent
import Control.Concurrent.STM.TMVar
import Control.Monad.STM
newtype LastToFinishSTM a = LastToFinishSTM { runLastToFinish :: STM a }
instance Semigroup (LastToFinishSTM a) where
@coot
coot / Pipelined.hs
Last active May 4, 2021 14:24
Explicit pipelining without concurrency
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE EmptyCase #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE StandaloneDeriving #-}
@coot
coot / viewport.vim
Last active November 20, 2020 18:47
View portion of a buffer, mapped through BufWriteCmd file to the original buffer.
" Author: Marcin Szamotulski, © 2012-2020
" License: Vim-License, see :help license
fun! ViewPort(cmd, s_line, e_line, ...) " {{{1
if !has("autocmd")
echohl WarningMsg
echom "[ViewPort]: requires +autocmd feature"
echohl Normal
return
endif
@coot
coot / FlipFlops.hs
Last active September 27, 2020 08:14
Flip-Flops
{-# LANGUAGE NamedFieldPuns #-}
-- | https://en.wikipedia.org/wiki/Flip-flop_(electronics)#SR_NOR_latch
module FlipFlops
( -- * Logic primitives
-- * SR-NOR--Latch
SRNORLatch
, mkSRNORLatch
, runSRNORLatch
-- ** SR-NAND--Latch
@coot
coot / dwm.vim
Last active February 5, 2020 12:36
Simple dwm like window managment for vim
" Simple DWM like window managment for vim windows
fun! WinFocus(winnr)
" this assumes that windows have a two column layer: master windows on the
" left, and right column consists of a list of opened windows
if a:winnr == 0
let l:winnr = winnr()
else
let l:winnr = a:winnr
endif
if l:winnr == 1
@coot
coot / Control.Cateogory.Tracer.hs
Last active August 6, 2019 21:40
Tracer using `Arrow` categories
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Prelude hiding (filter, (.))
import Control.Arrow
import Control.Category
data TracerC c a where
@coot
coot / Naturals.agda
Last active June 23, 2019 21:28
Natural numbers - simple formal proofs in Agda & Haskell
module Naturals where
-- based on https://plfa.github.io/
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; sym; trans)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎)
data ℕ : Set where
zero : ℕ
@coot
coot / keybase.md
Created December 17, 2018 00:07
keybase.io proof

Keybase proof

I hereby claim:

  • I am coot on github.
  • I am coot (https://keybase.io/coot) on keybase.
  • I have a public key ASA4C4mk10e3x-LowdhnXeF8_qd8-tK_UhiEfw47z8u6zwo

To claim this, I am signing this object:

@coot
coot / Main.purs
Last active April 22, 2018 15:01
PureScript: pick subrecords from a record.
module Main where
import Prelude
import Data.Foldable (fold, elem)
import TryPureScript
import Type.Row (class ListToRow, class RowToList, Cons, Nil, kind RowList)
import Type.Proxy (Proxy(..))
import Type.Data.Symbol (class IsSymbol, reflectSymbol)
import Data.Array (cons)
import Data.Monoid (mempty)