This file contains hidden or 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
| #!/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"完美世界" |
This file contains hidden or 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
| # 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') |
This file contains hidden or 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
| 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): |
This file contains hidden or 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
| // 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 |
This file contains hidden or 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
| // 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" |
This file contains hidden or 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
| package main | |
| import "fmt" | |
| func qsort(data []int) { | |
| if len(data) <= 1 { | |
| return | |
| } | |
| mid, i := data[0], 1 | |
| head, tail := 0, len(data)-1 |
This file contains hidden or 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
| // http://tour.golang.org/#52 | |
| // code - 1 | |
| package main | |
| import ( | |
| "fmt" | |
| "math" | |
| ) | |
This file contains hidden or 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
| // http://tour.golang.org/#58 | |
| package main | |
| import ( | |
| "fmt" | |
| ) | |
| type ErrNegativeSqrt float64 |
This file contains hidden or 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
| 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] |
This file contains hidden or 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
| #!/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 = [] |
OlderNewer