Skip to content

Instantly share code, notes, and snippets.

@KWMalik
KWMalik / LinearSelection.hs
Created July 30, 2012 20:08 — forked from supki/LinearSelection.hs
Linear complexity selection algorithm (from Algo class at coursera).
module LinearSelection where
import System.Random (randomRIO)
import System.IO.Unsafe (unsafePerformIO)
select :: Ord a => [a] -> Int -> a
select [x] 1 = x
select xs n
| n > length xs || n <= 0 = error $ "select: wrong index (" ++ show n ++ ") where length is " ++ show (length xs)
| length ls < n = select bs (n - length ls)
@KWMalik
KWMalik / Queue.hs
Created July 30, 2012 20:07 — forked from supki/Queue.hs
Okasaki's purely functional queues.
{-# LANGUAGE UnicodeSyntax #-}
module Queue
( Queue
, isEmpty
, ($*), head, tail
, size
, fromList
) where
import Data.List (foldl')
@KWMalik
KWMalik / QuickSort.hs
Created July 30, 2012 20:07 — forked from supki/QuickSort.hs
Semi-parallel pseudo-randomized in-place quicksort in Haskell.
{-# LANGUAGE UnicodeSyntax #-}
module Main (main) where
import Control.Applicative ((<$>))
import Control.Monad (foldM, when)
import Control.Monad.ST (ST)
import Control.Parallel (par)
import Data.Array (elems)
import Data.Array.ST (STArray, newListArray, readArray, runSTArray, writeArray)
import Data.Char (toUpper)
@KWMalik
KWMalik / Pisya.hs
Created July 30, 2012 20:07 — forked from supki/Pisya.hs
Construct $name = putStrLn "$name" function via Template Haskell.
{-# LANGUAGE TemplateHaskell #-}
module Pisya where
import PisyaTH
$(anal ["pemis", "gnoi", "sosiska", "sobachka"])
@KWMalik
KWMalik / NFA.hs
Created July 30, 2012 20:07 — forked from supki/NFA.hs
Simple NFA-driven regexp engine.
{-# LANGUAGE UnicodeSyntax #-}
module NFA
( single, (×), (⧺), star
) where
import Data.Maybe (fromMaybe, mapMaybe)
import Prelude hiding (concat)
import qualified Prelude
data NFA p = NFA { match ∷ (p → Maybe [p]) }
@KWMalik
KWMalik / hackage-authors.pl
Created July 30, 2012 20:06 — forked from supki/hackage-authors.pl
Silly stuff to get hackage authors sorted by productivity.
#!/usr/bin/env perl
# This crappy perl script parses .cabal files for `authors' field and extracts authors names. Then it collects them in one enormous hash associating total number of findings. Then it "pretty"-prints hash from most productive authors to least productive.
use v5.14;
use warnings FATAL => qw(void);
# Skip all lines before /^author:/i one, then return it.
sub lex ($) {
my $h = $_[0];
while (<$h>) { if (/^author:/i) { return $_ } }
{-# LANGUAGE UnicodeSyntax #-}
module Main where
import Control.Monad (replicateM)
import Data.Functor ((<$>))
import Data.IntMap (IntMap, (!))
import Data.Maybe (fromJust)
import System.Environment (getArgs)
import System.Random (randomRIO)
import qualified Data.IntMap as IM
@KWMalik
KWMalik / all-your-modules.hs
Created July 30, 2012 20:05 — forked from supki/all-your-modules.hs
Module dependency graph generating scripts.
#!/usr/bin/env runhaskell
{-# LANGUAGE UnicodeSyntax #-}
import Control.Applicative ((<$>))
import Control.Monad ((<=<))
import Data.List (intercalate)
import System.Environment (getArgs)
import Distribution.ModuleName (components)
import Distribution.PackageDescription (condLibrary, condTreeData, libModules)
@KWMalik
KWMalik / Main.hs
Created July 30, 2012 20:04 — forked from supki/Main.hs
Cryptography coursera class exercise #6.
{-# LANGUAGE UnicodeSyntax #-}
import Data.Char (chr)
import Text.Printf (printf)
import Data.List.Split (chunk)
import Data.Number.CReal (CReal)
main ∷ IO ()
main =
@KWMalik
KWMalik / Main.hs
Created July 30, 2012 20:04 — forked from supki/Main.hs
Cryptography coursera class exercise #5.
{-# LANGUAGE UnicodeSyntax #-}
import Control.Monad (foldM_, join)
import qualified Data.HashMap.Lazy as H
b ∷ Int
b = 1048576
p ∷ Integer