Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / algorithms.hs
Created July 30, 2012 20:08 — forked from supki/algorithms.hs
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
@KWMalik
KWMalik / w1q1.py
Created July 30, 2012 21:14 — forked from raullenchai/w1q1.py
Solve Week 1 Question 1 in Stanford Crypto Course
CT = ( '315c4eeaa8b5f8aaf9174145bf43e1784b8fa00dc71d885a804e5ee9fa40b16349c146fb778cdf2d3aff021dfff5b403b510d0d0455468aeb98622b137dae857553ccd8883a7bc37520e06e515d22c954eba5025b8cc57ee59418ce7dc6bc41556bdb36bbca3e8774301fbcaa3b83b220809560987815f65286764703de0f3d524400a19b159610b11ef3e','234c02ecbbfbafa3ed18510abd11fa724fcda2018a1a8342cf064bbde548b12b07df44ba7191d9606ef4081ffde5ad46a5069d9f7f543bedb9c861bf29c7e205132eda9382b0bc2c5c4b45f919cf3a9f1cb74151f6d551f4480c82b2cb24cc5b028aa76eb7b4ab24171ab3cdadb8356f', '32510ba9a7b2bba9b8005d43a304b5714cc0bb0c8a34884dd91304b8ad40b62b07df44ba6e9d8a2368e51d04e0e7b207b70b9b8261112bacb6c866a232dfe257527dc29398f5f3251a0d47e503c66e935de81230b59b7afb5f41afa8d661cb', '32510ba9aab2a8a4fd06414fb517b5605cc0aa0dc91a8908c2064ba8ad5ea06a029056f47a8ad3306ef5021eafe1ac01a81197847a5c68a1b78769a37bc8f4575432c198ccb4ef63590256e305cd3a9544ee4160ead45aef520489e7da7d835402bca670bda8eb775200b8dabbba246b130f040d8ec6447e2c767f3d30ed81ea2e4c1404e1315a1010e7229be6636aaa', '3f561ba9adb4b6ebec544
@KWMalik
KWMalik / gist:3214387
Created July 31, 2012 06:56 — forked from yesez/gist:3214190
Singleton
Public NotInheritable Class Singleton
Private Shared _Instance As Singleton = Nothing
Private Shared ReadOnly _Sync As New Object
Private Sub New()
End Sub
Public Shared ReadOnly Property Instance() As Singleton
Get
@KWMalik
KWMalik / w1q2.py
Created July 31, 2012 07:05 — forked from raullenchai/w1q2.py
Solve Week 1 Question 2 in Stanford Crypto Course
CT = (210205973, 22795300, 58776750, 121262470, 264731963, 140842553, 242590528, 195244728, 86752752)
P = 295075153L # about 2^28
class WeakPrng(object):
def __init__(self, p, x, y): # generate seed with 56 bits of entropy
self.p = p
self.x = x
self.y = y
def next(self):
@KWMalik
KWMalik / task_1_1.ml
Created August 29, 2012 18:13 — forked from tilarids/task_1_1.ml
Solution for coursera's Cryptography programming task 1.1
open Batteries_uni
let regroup e n =
let next () =
if Enum.is_empty e then
raise Enum.No_more_elements
else
Enum.take n e in Enum.from next;;
let load_ciphers fname =