Skip to content

Instantly share code, notes, and snippets.

Avatar
🖤

Cheng Shao TerrorJack

🖤
View GitHub Profile
View wavio.py
# wavio.py
# Author: Warren Weckesser
# License: BSD 3-Clause (http://opensource.org/licenses/BSD-3-Clause)
import wave
import numpy as np
def _wav2array(nchannels, sampwidth, data):
"""data must be the string containing the bytes from the wav file."""
View gist:a61e9515a0320e7d4a4b
#include <memory>
#include <iostream>
template <typename T>
struct _list;
template <typename T>
using list = std::shared_ptr<_list<T>>;
template <typename T>
struct _list {
@TerrorJack
TerrorJack / gist:1fc8f0eb8a8a45f78f14
Last active Aug 29, 2015
Memoization in haskell
View gist:1fc8f0eb8a8a45f78f14
fib :: Int -> Integer
fib = head . makefib where
makefib 0 = [0]
makefib 1 = [1,0]
makefib n = (head nextfib + head (tail nextfib)):nextfib where nextfib = makefib $ n - 1
main :: IO ()
main = print $ fib 1000
View AnIntro.md

Basic unit type:

λ> replTy "()"
() :: ()

Basic functions:

@TerrorJack
TerrorJack / gist:224b21657cc82f079413
Created Dec 19, 2014
Call-by-value lambda calculus interpreter (which won't work)
View gist:224b21657cc82f079413
import qualified Data.Map as Map
type Env = Map.Map String Term
data Term =
VarTerm String
| IntTerm Int
| BoolTerm Bool
| LambdaTerm String Term
| AppTerm Term Term
@TerrorJack
TerrorJack / gist:a413ebced3494e2148a5
Created Dec 25, 2014
A simple interpreter (that works). Supports ADT/pattern matching. No type system/callcc/macro.
View gist:a413ebced3494e2148a5
import qualified Data.Map as Map
type Env = Map.Map String Val
data Exp =
ConstExp Val
| VarExp String
| LambdaExp Pat Exp
| LetrecExp [(Pat,Exp)] Exp
| IfExp Exp Exp Exp
@TerrorJack
TerrorJack / webproxy.json
Created Mar 14, 2015
Web proxies. Keys are domains, values indicate country, software and SSL support.
View webproxy.json
{"0010freeproxy.info": ["DE", "Glype", false], "0013freeproxy.info": ["DE", "Glype", false], "0021freeproxy.info": ["DE", "Glype", false], "007browser.info": ["US", "Glype", false], "123anonymous.com": ["US", "Glype", false], "1774.info": ["US", "Glype", false], "1agent.info": ["US", "Glype", false], "1block.info": ["US", "Glype", false], "1catch.info": ["US", "Glype", false], "1close.info": ["US", "Glype", false], "1closed.info": ["US", "Glype", false], "1force.info": ["US", "Glype", false], "1good.info": ["US", "Glype", false], "1lazy.info": ["US", "Glype", false], "1mesh.info": ["US", "Glype", false], "1proxy.us": ["US", "PHProxy", true], "1total.info": ["US", "Glype", false], "2999.info": ["US", "Glype", false], "2action.info": ["US", "Glype", false], "2closed.info": ["US", "Glype", false], "2fastsurfer.eu": ["US", "Glype", false], "2fix.info": ["US", "Glype", false], "2g23.com": ["US", "Glype", false], "2g34.com": ["US", "Glype", false], "2gram.info": ["US", "Glype", false], "2insta.info": ["US", "Glype"
@TerrorJack
TerrorJack / icfp.json
Created Mar 25, 2015
some acm data for fun.
View icfp.json
This file has been truncated, but you can view the full file.
{
"event_title": "International Conference on Functional Programming",
"event_contents": [
{
"conference_title": "Commercial Users of Functional Programming",
"conference_contents": [
{
"proceeding_title": "CUFP '10:ACM SIGPLAN Commercial Users of Functional Programming",
"proceeding_contents": [
@TerrorJack
TerrorJack / gist:95a964c649c325c8bf87
Last active Aug 29, 2015
A minimal PEG parsing library.
View gist:95a964c649c325c8bf87
import Control.Applicative
import Control.Monad.State
import Data.Char
import Data.Function
type Parser = StateT String Maybe
parse :: Parser a -> String -> Maybe (a,String)
parse = runStateT
@TerrorJack
TerrorJack / gist:7844978a7db17d836d18
Last active Aug 29, 2015
By now, only fibState works. All other functions cause memory overflow.
View gist:7844978a7db17d836d18
{-
Different ways to implement Fibonacci function in Haskell.
F(0)=0 F(1)=1 F(n)=F(n-1)+F(n-2)
-}
import Control.Monad.State.Strict
import Control.Monad.ST.Strict
import Data.STRef.Strict
import System.TimeIt
You can’t perform that action at this time.