Skip to content

Instantly share code, notes, and snippets.

View scturtle's full-sized avatar
🐢

scturtle

🐢
View GitHub Profile
@scturtle
scturtle / hack.py
Created March 3, 2014 09:10
hack the image puzzle LEVEL2 of http://www.guokr.com/post/557047/
# http://five.flash-gear.com/npuz/puz.php?c=z&o=2&id=4349105&k=17041499&s=15&w=420&h=555&f_dm=five
data = open('puz.swf', 'rb').read()
mark = '\xff\xd8\xff\xe0\x00\x10JFIF'
t=data.split(mark)
for i, d in enumerate(t):
if 'CREATOR' in d:
open('%d.jpeg'%i, 'wb').write(mark + d)
@scturtle
scturtle / calc.hs
Last active August 29, 2015 13:57
calc with parsec
import Text.Parsec
import Text.Parsec.Expr
import Text.Parsec.Language (emptyDef)
import Text.Parsec.String (Parser)
import qualified Text.Parsec.Token as P
lexer = P.makeTokenParser emptyDef
parens = P.parens lexer
number :: Parser Double
@scturtle
scturtle / tree.hs
Last active August 29, 2015 13:57
plot binary tree like a boss
import Data.Maybe (fromMaybe)
import Data.List (intercalate)
data Tree a = Tree {left :: Tree a, right :: Tree a, val :: a}
| Nil deriving (Eq)
instance (Eq a, Show a) => Show (Tree a) where
show = toString
genPosTree :: (Show a, Eq a) => Tree a -> Int -> Tree (a, Int, Int, Maybe Int, Maybe Int)
@scturtle
scturtle / get163book.py
Created March 18, 2014 03:59
163 reader
import requests
import base64
from bs4 import BeautifulSoup
cookie = open('cookie163.txt').read().strip()
bookid = '23c816b98303491ab82e898d349f6154_4&tradeId='
bookinfo = requests.get('http://yuedu.163.com/getBook.do?id='+bookid).json()
content = ''
for p in bookinfo['portions']:
@scturtle
scturtle / mandelbrot.py
Created April 20, 2014 10:15
Mandelbrot demo
''' http://nbviewer.ipython.org/gist/anonymous/f5707335f40af9463c43 '''
try:
import numpy as np
except:
import numpypy as np
def mandel(x, y, max_iters):
c = complex(x, y)
z = 0.0j
@scturtle
scturtle / bf.hs
Created April 28, 2014 02:57
Brainfuck Intepreter
{-# OPTIONS_GHC -O2 -optc-O2 #-}
import Control.Monad
import Text.ParserCombinators.Parsec
import Control.Monad.State
import Data.Array.IO
import Data.Char
import Debug.Trace
data Stmt = INCPNT | DECPNT | INC | DEC | OUTPUT | READ
| Loop [Stmt]
@scturtle
scturtle / test.bf
Created April 30, 2014 07:28
print 0 to 99 in brainfuck
ref: http://www'iwriteiam'nl/Ha_bf_intro'html
>++++++++++[<++++++++++>-] (#0=100)
>+++++++[<+++++++>-]+++++++++++<--< (#1=47 #2=11)
[ (loop #0)
>+ (inc #1)
>- (dec #2)
(test if #2 is 0 using #3 #4)
[>+>+<<-] >[<+>-] (move #2 to #3 #4; move #3 to #2)

Keybase proof

I hereby claim:

  • I am scturtle on github.
  • I am scturtle (https://keybase.io/scturtle) on keybase.
  • I have a public key whose fingerprint is C781 C6A7 A71A FFBA D1CD 08DA 899C 7671 AF1A 9565

To claim this, I am signing this object:

@scturtle
scturtle / avl.hs
Last active August 29, 2015 14:02
AVL tree in haskell (insert and select)
data AVL a = Null | Branch a (AVL a) (AVL a) Int Int -- height size
deriving Show
height :: AVL a -> Int
height Null = 0
height (Branch _ _ _ h _) = h
size :: AVL a -> Int
size Null = 0
size (Branch _ _ _ _ s) = s
@scturtle
scturtle / yanwenzi
Last active August 29, 2015 14:03
颜文字
🎵
「」
╮( ̄▽ ̄")╭
┐(・ิL_・ิ)┌
ˊ_>ˋ
(#°Д°)
_(:3」∠)_
→_→
﹁ ﹁
눈_눈