This file contains 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 Data.List | |
import Data.Function | |
import Control.Monad | |
groupOn f = groupBy ((==) `on` f) . sortBy (compare `on` f) | |
uniq = map (!! 0) . groupOn id | |
-- 场景:假设a得到了数字x,b得到了数字y | |
-- 可看做二分图,其中possibleX,possibleY是顶点,possible是边,(aGuessY x)和(bGuessX y)分别表达x点和y点的邻接点集 | |
possible = [(5, 15), (5, 16), (5, 19), (6, 17), (6, 18), (7, 14), (7, 16), (8, 14), (8, 15), (8, 17)] |
This file contains 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
require 'coffee-mate/global' | |
compareDictOn = (f) -> | |
(da, db) -> | |
[da, db] = [f(da), f(db)] | |
for k, va of da | |
vb = db[k] | |
if (not vb?) or (va < vb) | |
return -1 | |
else if (not va?) or (va > vb) |
This file contains 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
isPrime x = all (\p -> x `mod` p /= 0) . takeWhile ((<= x) . (^ 2)) $ primes | |
primes = 2 : 3 : filter isPrime [5..] |
This file contains 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
{-# language NoMonomorphismRestriction #-} | |
import Control.Monad | |
import Test.QuickCheck hiding (scale) | |
import Codec.BMP | |
import qualified Data.ByteString | |
import Data.Word | |
--------------------- Point & Vec etc ---------------------- | |
type Scalar = Double |
This file contains 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
#resolver: ghc-7.8.4 | |
resolver: ghc-7.10.2 | |
packages: | |
- '.' | |
extra-deps: | |
- SourceGraph-0.7.0.7 | |
- Graphalyze-0.14.1.1 |
This file contains 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
capitalize = (s) -> s.replace /(?:_|^)([a-z])/g, (_, c) -> c.toUpperCase() # 'hello_world' to 'HelloWorld' | |
uncapitalize = (s) -> s.replace /([A-Z])/g, (_, c) -> '_' + c.toLowerCase() # 'HelloWorld' to 'hello_world' | |
is_chinese_char = (c) -> /[\u4E00-\u9FA5\uF900-\uFA2D]/.test c |
This file contains 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
#!/bin/sh | |
# add this file to your path so that you can run it as an git command via `git checkoutr xxx` | |
br=$1 | |
test -z $br || git checkout $br | |
git submodule update --init --recursive |
This file contains 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
ffmpeg -loglevel panic -f rawvideo -pix_fmt bgr32 -s 2560x1440 -i screenshot.raw -vcodec png -vframes 1 screenshot.png -y |
This file contains 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
#coding:utf-8 | |
import subprocess | |
import time | |
from PIL import Image | |
def call(cmd): | |
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
return proc.stdout.read() | |
### general tools |
OlderNewer