Skip to content

Instantly share code, notes, and snippets.

@hipro
hipro / getepub_qidian.py
Last active December 31, 2015 08:09
Get a public section epub file from qidian.com.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
test link:
num: number of entries per page.
q: query keys
https://www.google.com.hk/search?num=1&q=site:qidian.com+intitle:"完美世界"
https://www.google.com.hk/search?hl=zh-CN&qscrl=1&num=1&q=site%3Aqidian.com+intitle%3A"完美世界"
# 1.
from os import walk, makedirs, remove, rmdir
from os.path import join
# copy directory tree.
for r,ds,fs in walk('old'):
for d in ds:
makedirs(join('new',d))
for f in fs:
of=file(join(r,f),'rb')
@hipro
hipro / decorator.py
Last active January 1, 2016 21:09
@ decorator
def mc():
def d(fun):
def wrapper(*args, **kwargs):
print args,kwargs
return fun(*args, **kwargs)
return wrapper
return d
def d(fun):
def wrapper(*args, **kwargs):
@hipro
hipro / fibonacci.go
Created September 26, 2014 08:52
Let's have some fun with functions. Implement a fibonacci function that returns a function (a closure) that returns successive fibonacci numbers.
// http://tour.golang.org/#46
// Let's have some fun with functions.
// Implement a fibonacci function that returns a function (a closure)
// that returns successive fibonacci numbers.
package main
import "fmt"
// fibonacci is a function that returns
@hipro
hipro / cuberoots.go
Created September 26, 2014 09:29
Find the cube root of 2, just to make sure the algorithm works. There is a Pow function in the math/cmplx package.
// http://tour.golang.org/#50
// Let's explore Go's built-in support for complex numbers via the complex64 and complex128 types.
// For cube roots, Newton's method amounts to repeating:
// z = z - (z*z*z - x) / (3 * z*z)
// Find the cube root of 2, just to make sure the algorithm works.
// There is a Pow function in the math/cmplx package.
package main
import "fmt"
@hipro
hipro / qsort.go
Last active August 29, 2015 14:06
package main
import "fmt"
func qsort(data []int) {
if len(data) <= 1 {
return
}
mid, i := data[0], 1
head, tail := 0, len(data)-1
@hipro
hipro / methods.go
Created September 28, 2014 02:43
两个代码的结果相同。v *Vertex ---- v Vertex
// http://tour.golang.org/#52
// code - 1
package main
import (
"fmt"
"math"
)
// http://tour.golang.org/#58
package main
import (
"fmt"
)
type ErrNegativeSqrt float64
@hipro
hipro / get_func_args_dict.py
Created October 13, 2014 08:57
获取一个函数的参数列表
class FuncArgsDict(object):
@staticmethod
def generate_dic(f, args):
return {k: v for (k, v) in zip(f.func_code.co_varnames[1:], args)}
def func(self, a, b, c):
kws = self.generate_dic(self.func, [a, b, c])
for k in kws:
print k, ':', kws[k]
#!/usr/bin/env python2.7
#-*- coding: utf-8 -*-
from hashlib import md5
from fabric.api import env, run, cd, local # , settings
from fabric.tasks import execute
from fabric.decorators import with_settings # , task
from datetime import datetime as dt, timedelta
result = []