Skip to content

Instantly share code, notes, and snippets.

View damhiya's full-sized avatar

SoonWon Moon damhiya

View GitHub Profile
@damhiya
damhiya / Replicate2.hs
Created February 25, 2021 07:45
haskell laziness
replicate2 :: Int -> a -> a -> [a]
replicate2 n x y = as where
(as, bs) = go n bs []
go 0 as bs = (as, bs)
go n as bs = go (n-1) (x:as) (y:bs)
@damhiya
damhiya / fft.cpp
Created February 23, 2021 14:10
c++ fft
#include <iostream>
#include <vector>
#include <complex>
#include <cmath>
#include <cstdint>
#include <immintrin.h>
const uint8_t flip_nibble[16] = {
0, 8, 4, 12,
@damhiya
damhiya / DNEtoEM.hs
Created February 18, 2021 20:06
double negation elimination -> law of excluded middle (point-free)
{-# LANGUAGE RankNTypes #-}
module DNEtoEM where
data Bottom
type Not a = a -> Bottom
type DNE = forall a. Not (Not a) -> a
type EM = forall a. Either a (Not a)
@damhiya
damhiya / Sort.hs
Last active February 10, 2021 08:01
haskell merge sort using ST monad
module Sort where
import Control.Monad.ST
import Data.Vector as V
import Data.Vector.Mutable as MV
sort :: Ord a => Vector a -> Vector a
sort v =
if V.length v <= 1 then
v
@damhiya
damhiya / Powf.hs
Created January 25, 2021 17:02
apply function n times in haskell
import Data.Monoid
import Data.Functor.Const
powf :: (a -> a) -> Int -> a -> a
powf f n = (appEndo . getConst . replicateM_ n . Const . Endo) f
@damhiya
damhiya / configuration.nix
Last active April 4, 2021 10:06
kime for nix
let
kime = import ./pkgs/kime.nix;
gtk3_cache = pkgs.runCommand "gtk3-immodule.cache"
{ preferLocalBuild = true;
allowSubstitutes = false;
buildInputs = [ pkgs.gtk3 kime ];
}
''
mkdir -p $out/etc/gtk-3.0/
GTK_PATH=${kime}/lib/gtk-3.0/ gtk-query-immodules-3.0 > $out/etc/gtk-3.0/immodules.cache
@damhiya
damhiya / Automaton.hs
Created December 31, 2020 07:06
Powerset construction algorithm (NFA to DFA conversion)
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Automaton where
import Data.Maybe
import Data.Map as M
import Data.Set as S
import Data.IntMap as IM
import Data.IntSet as IS