Skip to content

Instantly share code, notes, and snippets.

@cleichner
cleichner / HkdZip.hs
Last active May 7, 2021 22:50
Example code to explore the example from https://www.youtube.com/watch?v=sIqZEmnFer8 without the use of the 'barbies' library
-- Copyright 2021 Google LLC.
-- SPDX-License-Identifier: Apache-2.0
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
module Main where
import Data.Functor.Identity
import Data.Functor.Product

Keybase proof

I hereby claim:

  • I am cleichner on github.
  • I am chas (https://keybase.io/chas) on keybase.
  • I have a public key whose fingerprint is EB53 7E69 EAAC 25ED F926 9C92 4C07 A6D8 BE65 FBF6

To claim this, I am signing this object:

@cleichner
cleichner / wrapM.hs
Last active August 29, 2015 14:02
wrapM
wrapM :: Monad m => (a -> b) -> (a -> m b)
wrapM = (return .)
-- same as wrapM f = \x -> return (f x)
module KleisliComp where
import Control.Arrow
import Data.Foldable
import Data.Monoid
import Data.Monoid.Endomorphism
-- After explicitly writing the KleisliEndo instance, I realized that it could
-- be built using existing infrastructure, namely the Kleisli category instance
-- and the Monoid instance for category endomorphism composition.
import Criterion.Main
prswap [] = []
prswap (a:b:xs) = b:a:prswap xs
prswap' [] = []
prswap' list = reverse (take 2 list) ++ prswap (drop 2 list)
main = defaultMain [ bgroup "prswap" [ bench "prswap [1..1000]" $ whnf prswap [1..1000]
, bench "prswap [1..10000]" $ whnf prswap [1..10000]
@cleichner
cleichner / cleichner.hs
Last active January 2, 2016 20:59
The laziest high-performance bf compiler ever.
import Control.Monad
import Data.List
data BF a = Add a
| Move a
| StartLoop
| EndLoop
| Write
| Read
| Zero
@cleichner
cleichner / null.py
Created October 27, 2013 00:09
This eats nearly everything that it interacts with.
'''
Null module:
Responds to all actions and requests for members with a null object.
For example, this code will execute the debugging tools in development, but
won't do anything in production.
if environment == development:
import ExpensiveDebugging
else:
@cleichner
cleichner / butts
Last active December 22, 2015 04:18
Command-line utility to display Lady's "Twerk" video.
#!/usr/bin/env python
'''
The MIT License (MIT)
Copyright (c) 2013 Chas Leichner
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
@cleichner
cleichner / LICENSE
Last active December 20, 2015 06:29
I re-wrote a toy Java program in Haskell and messed with the style ... a lot.
Copyright 2014 Chas Leichner
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
@cleichner
cleichner / 16x16 maze
Created July 27, 2012 18:41
Maze Parsing
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
| _ _ _ _ | _ _ _ _ _ |
| |_|_ |_|_ _| _|_ _ _| |
| |_ _|_ | |_| |_ _ _| |_|
|_| |_ _ _|_ _ _| |_ _|
| | |_ _ | |_|_|_ | _|_ |
| _| | |_|_ _| |_ _ | |
| | | _| |_| |_ _ _| | |
| |_| |_|_ _ | |_ _|_ _|_ | |
|_| _| _ _ _| | | | _ _ | |_|