Skip to content

Instantly share code, notes, and snippets.

View yihuang's full-sized avatar
🏠
Working from home

yihuang yihuang

🏠
Working from home
  • crypto.com
  • Shenzhen, China
View GitHub Profile
@yihuang
yihuang / bench.py
Created July 18, 2014 03:44
benchmark cython property
import pyximport; pyximport.install()
class PurePlayer(object):
def __init__(self):
self.__age = 0
def set_age(self, value):
self.__age = value
def get_age(self):
{-# LANGUAGE ExistentialQuantification, GeneralizedNewtypeDeriving #-}
import System.FilePath (FilePath, (</>))
import System.Directory (getDirectoryContents, doesFileExist)
import Control.Monad
import Control.Monad.State
import Control.Monad.Reader
import Control.Monad.Writer
type St = Int
data Conf = Conf {
{-# LANGUAGE FlexibleInstances, TypeSynonymInstances, RankNTypes, OverloadedStrings #-}
import Data.Data
import Data.Aeson hiding (toJSON, fromJSON)
import Data.Aeson.Generic
import Data.Attoparsec
import qualified Data.ByteString as B
data MethodCall = MethodCall String [Value]
deriving (Eq, Show)
@yihuang
yihuang / cabal-install-ghc722.patch
Created December 5, 2011 05:43
patch to bootstrap cabal-install under ghc-7.2.2
diff --git a/bootstrap.sh b/bootstrap.sh
index b9950e7..105b693 100644
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -19,7 +19,7 @@ CURL=${CURL:-curl}
FETCH=${FETCH:-fetch}
TAR=${TAR:-tar}
GUNZIP=${GUNZIP:-gunzip}
-SCOPE_OF_INSTALLATION="--user"
+SCOPE_OF_INSTALLATION="--global"
@yihuang
yihuang / gist:1481667
Created December 15, 2011 16:12
copy directory recursively
import Prelude hiding (catch)
import System.Environment
import System.IO
import System.Directory
import System.FilePath
import Control.Exception
import Control.Applicative
import Control.Monad
import Data.List
@yihuang
yihuang / trie.hs
Created February 27, 2012 12:46
naive trie map in haskell
import Prelude hiding (lookup)
import Data.Maybe (fromMaybe)
import qualified Data.Map as M
import Control.Monad (join)
data Trie c a = Trie
(Maybe a) -- node may or may not contain a value.
(M.Map c (Trie c a))
deriving (Show)
@yihuang
yihuang / euler14.hs
Created March 23, 2012 11:39
project euler 14
import Criterion.Main
next :: Int -> Int
next n | even n = n `div` 2
| otherwise = 3*n+1
len :: Int -> Int
len = length . takeWhile (/=1) . iterate next
len' :: Int -> Int -> Int
@yihuang
yihuang / lazy_vs_st.hs
Created March 26, 2012 13:32
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)
@yihuang
yihuang / lazy_vs_st.hs
Created March 27, 2012 00:51 — forked from qzchenwl/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 Criterion.Main
fib1 :: Int -> Integer
fib1 n = fst $ fib' n
where fib' 0 = (1, 1)
@yihuang
yihuang / dlist.hs
Created March 28, 2012 04:24
dlist
module DList where
import Prelude hiding (reverse)
import Prelude as P
{-
- provide whatever list operation in O(1) time complexity ...
- only toList do all the hard works.
-}