Skip to content

Instantly share code, notes, and snippets.

@qzchenwl
qzchenwl / OAuth2.hs
Created April 10, 2012 12:34
Simple oauth2.0 implementation in Haskell
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveDataTypeable #-}
import Data.Aeson
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.ByteString.Lazy (toChunks)
import Data.List
import Data.Maybe
import Data.Typeable (Typeable)
{-# LANGUAGE BangPatterns #-}
module Main where
import Data.List (transpose)
import Criterion.Main
naiveFib, cachedFib, cachedFib', tailrFib, tailrFib', matrixFib
:: Integer -> Integer
naiveFib 0 = 0
@qzchenwl
qzchenwl / rsa.hs
Created April 2, 2012 17:35
simple RSA implementation
module RSA where
-- extendedGcd(a,b) = (x,y), such that a*x + b*y = gcd(a,b)
extendedGcd :: Integral a => (a, a) -> (a, a)
extendedGcd (a, b) = if b == 0 then (1, 0) else (x, y)
where
(q, r) = divMod a b
(s, t) = extendedGcd (b, r)
(x, y) = (t, s - q * t)
@qzchenwl
qzchenwl / lazy_vs_st.hs
Created March 27, 2012 03:43 — forked from yihuang/lazy_vs_st.hs
lazy vs ST
{-# LANGUAGE BangPatterns #-}
module Main (fib1, fib2, fib3, fib4, main) where
import Control.Monad
import Control.Monad.ST
import Data.STRef
import Data.List (transpose)
import Criterion.Main
fib1 :: Int -> Integer
fib1 n = fst $ fib' n
@qzchenwl
qzchenwl / lazy_vs_st.hs
Created March 26, 2012 17:17 — forked from yihuang/lazy_vs_st.hs
lazy vs ST
{-# LANGUAGE BangPatterns, ViewPatterns #-}
import System.Environment (getArgs)
import Control.Monad
import Control.Monad.ST
import Data.STRef
import GHC.Int
fib1 :: Int -> Integer
fib1 n = fibs !! n
where fibs = 1 : 1 : zipWith (+) fibs (tail fibs)
@qzchenwl
qzchenwl / simple-schema.hs
Created February 26, 2012 10:42
implement sub schema in haskell
{-# LANGUAGE ExistentialQuantification #-}
module Main where
import Debug.Trace(traceShow)
import System.Environment
import Text.ParserCombinators.Parsec hiding (spaces)
import Control.Applicative ((<$>))
import Control.Monad.Error
import Data.IORef
import IO hiding (try)
@qzchenwl
qzchenwl / 2011-2012.hs
Created February 23, 2012 14:19
puzzle
module Main where
import Data.Ratio
import Data.Tree
data Label = Label
{ f1 :: (Rational -> Rational)
, accept :: Bool
, f2 :: (Rational -> Rational)
@qzchenwl
qzchenwl / 2011[2].hs
Created February 23, 2012 11:00
puzzle
module Main where
import Data.Ratio
import Data.Tree
data Label = Label
{ f1 :: (Rational -> Rational)
, accept :: (Rational -> Bool)
, f2 :: (Rational -> Rational)
@qzchenwl
qzchenwl / unzip.hs
Created February 14, 2012 10:29
unzip file
{-# LANGUAGE OverloadedStrings #-}
import Codec.Archive.Zip
import Data.ByteString.Lazy (getContents, putStrLn)
import Data.ByteString.Lazy.Char8 (ByteString)
import Prelude hiding (getContents, putStrLn)
import Data.Maybe (maybe)
import System.Environment (getArgs)
import System.Exit (exitFailure)
main = do filePath <- getArgs >>= parse
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
'''
convert Microsoft Word 2007 docx files to wiki markup files
'''
from lxml import etree
import zipfile
import string
import sys