This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
qsort :: Ord a => [a] -> [a] | |
qsort [] = [] | |
qsort (x:xs) = qsort small ++ [x] ++ qsort big | |
where small = [x'| x' <- xs, x' < x] | |
big = [x'| x' <- xs, x' >= x] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Levels of tests | |
o unit test | |
o integration test | |
o system test | |
o acceptance test | |
* Why test? (acceptance test / system test) | |
o verify correctness: bugs always exist (but we can keep them small and easier to solve) | |
o save manually verification time | |
* Why unit test? | |
o help find root of bugs (save debugging time) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Test.QuickCheck | |
import Data.List | |
-- | |
-- aux functions for verifications | |
-- | |
isOrdered :: Ord a => [a] -> Bool | |
isOrdered [] = True | |
isOrdered [x] = True | |
isOrdered (x:x2:xs) = x <= x2 && isOrdered (x2:xs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- wc.hs: word count | |
-- | |
-- Given a file name in the first command line argument, | |
-- print WORD: COUNT for each WORD per line. | |
-- The output is ordred by COUNT. | |
-- | |
import System | |
import Data.List |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.IO | |
import Data.Char(toUpper) | |
main = do | |
inh <- openFile "input.txt" ReadMode | |
outh <- openFile "output.txt" WriteMode | |
inpStr <- hGetContents inh | |
hPutStr outh (map toUpper inpStr) | |
hClose inh | |
hClose outh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.IO | |
import Data.Char(toUpper) | |
main = do | |
inh <- openFile "input.txt" ReadMode | |
outh <- openFile "output.txt" WriteMode | |
inpStr <- hGetContents inh | |
hClose inh | |
hPutStr outh (map toUpper inpStr) | |
hClose outh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function set_hg_rep() { | |
hg_rep=$(pwd | awk -F/ '{ print $5 }') | |
if [ "$hg_rep" != "" ]; then | |
hg_rep="(\033[1;31m$(pwd | awk -F/ '{ print $5 }')\033[m)" | |
fi | |
export PS1="[\u@wiki \w $hg_rep]\n$ " | |
} | |
function my_cd() { | |
\cd $1 && set_hg_rep |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- encoding: utf8 -*- | |
class A(object): | |
def __init__(self, s): | |
self.s = s | |
def __str__(self): | |
return self.s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 function gp() { | |
20 if [ "$1" = "-p" ]; then | |
21 shift | |
22 \ls *.py */*.py | perl -ne 'print $_ if !($_ =~ /.*_test\.py/)' | xargs grep -i --color $1 | |
23 elif [ "$1" = "-t" ]; then | |
24 shift | |
25 \ls *.py */*.py | perl -ne 'print $_ if $_ =~ /.*_test\.py/' | xargs grep -i --color $1 | |
26 else | |
27 g "$1" *.py */*.py | |
28 fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# demonstrate built-in functions' efficiency. | |
import timeit | |
import random | |
# prepare test data | |
numbers = range(2) | |
a = [] | |
for n in numbers: |
OlderNewer