Skip to content

Instantly share code, notes, and snippets.

View supki's full-sized avatar
🇦🇲
🤝 🏳️‍🌈

Matvey Aksenov supki

🇦🇲
🤝 🏳️‍🌈
  • Gorgoroth, Mordor
View GitHub Profile
@supki
supki / algorithms.hs
Created March 17, 2012 15:04
Strings distance count algorithms from Stanford NLP course.
import Control.Arrow ((***), second)
import Data.Array
import Data.Function (on)
import Data.List (minimumBy)
data Action = Ins
| Del
| Sub
| Id
deriving Show
@supki
supki / LinearSelection.hs
Created March 26, 2012 19:05
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)
import Test.QuickCheck
import Tree
prop_id [] = True
prop_id xs = xs == (toList . fromList) xs
prop_elem x xs = (x `elem` xs) == (x `elemTree` fromList xs)
@supki
supki / Queue.hs
Created May 9, 2012 14:35
Okasaki's purely functional queues.
{-# LANGUAGE UnicodeSyntax #-}
module Queue
( Queue
, isEmpty
, ($*), head, tail
, size
, fromList
) where
import Data.List (foldl')
@supki
supki / QuickSort.hs
Created May 15, 2012 15:05
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)
@supki
supki / Pisya.hs
Created May 26, 2012 07:32
Construct $name = putStrLn "$name" function via Template Haskell.
{-# LANGUAGE TemplateHaskell #-}
module Pisya where
import PisyaTH
$(anal ["pemis", "gnoi", "sosiska", "sobachka"])
@supki
supki / NFA.hs
Created May 29, 2012 17:52
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]) }
@supki
supki / Main.hs
Created June 11, 2012 18:52
Cryptography coursera class exercise #1.
{-# LANGUAGE UnicodeSyntax #-}
module Main where
import Control.Applicative ((<$>))
import Control.Monad (forM_, when)
import Control.Monad.State (execState, modify)
import Data.Bits (Bits, xor)
import Data.Char (chr, isAlpha)
import Data.List (maximumBy, group, sort, zip4)
import Data.List.Split (splitEvery)
@supki
supki / Main.hs
Created June 15, 2012 15:27
Simple screenshot folding via gd library.
{-# LANGUAGE UnicodeSyntax #-}
module Main where
import Control.Applicative ((<$>))
import Data.List (foldr1)
import Graphics.GD (copyRegion, loadPngFile, newImage, savePngFile)
import System.Directory (getCurrentDirectory, getDirectoryContents)
import System.FilePath ((</>))
main ∷ IO ()
@supki
supki / Main.hs
Created June 15, 2012 16:27
Simple screenshot folding via repa library.
{-# LANGUAGE UnicodeSyntax #-}
module Main where
import Control.Applicative ((<$>))
import System.Directory (getDirectoryContents)
import System.FilePath ((</>))
import Data.Array.Repa.IO.DevIL
import qualified Data.Array.Repa as R
main ∷ IO ()