Skip to content

Instantly share code, notes, and snippets.

View scturtle's full-sized avatar
🐢

scturtle

🐢
View GitHub Profile
@scturtle
scturtle / doubanfm.py
Last active January 4, 2016 21:29
get doubanFM starred songs
import requests
import json
import os
data = {
'email': '[email protected]',
'password': '',
'app_name': 'radio_android',
'version': '606',
}
import cv2
import numpy as np
canny = rho = threshold = minLen = maxGap = None
def draw():
lines = cv2.HoughLinesP(canny, rho, np.pi / 180,
threshold, None, minLen, maxGap)
dst = cv2.cvtColor(canny, cv2.COLOR_GRAY2BGR)
@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 / evol.py
Created April 18, 2014 10:09
generic algorithm using DEAP
from deap import base, creator, tools, algorithms
from random import randint, random, gauss
from PIL import Image, ImageDraw
from functools import partial
from math import sqrt
import numpy
PIC = Image.open('head.jpg')
SIZE = 100
@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)