This file contains 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
# -*- coding:utf-8 -*- | |
import time | |
import logging | |
import string | |
import random | |
import hmac | |
import base64 | |
import hashlib | |
import requests |
This file contains 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
from collections import deque | |
def flatten(list_): | |
return list(iflatten(list_)) | |
def iflatten(list_): | |
seen = set() | |
list_ = deque(list_) |
This file contains 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" | |
"image" | |
"image/color" | |
"image/draw" | |
"image/jpeg" | |
"image/png" | |
"log" |
This file contains 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
func createImage(width int, height int, background color.RGBA) *image.RGBA { | |
rect := image.Rect(0, 0, width, height) | |
img := image.NewRGBA(rect) | |
draw.Draw(img, img.Bounds(), &image.Uniform{background}, image.ZP, draw.Src) | |
return img | |
} |
This file contains 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
import sys | |
class Stupid(Exception): | |
pass | |
class X: | |
def __getattr__(self, name): |
This file contains 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
In [74]: timeit.timeit(stmt='del dll[10000]', setup='from collections import deque;dll = deque(range(10**5))', number=100) | |
Out[74]: 0.002535041014198214 | |
In [75]: timeit.timeit(stmt='del l[10000]', setup='l = list(range(10**5))', number=100) | |
Out[75]: 0.006009762000758201 |
This file contains 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
s = "s = {:c}{}{:c}{:c}print(s.format(34, s, 34, 10))" | |
print(s.format(34, s, 34, 10)) |
This file contains 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
import random | |
def setup_doors(): | |
doors = [0] * 3 | |
doors[random.choice(range(3))] = 1 | |
return doors | |
def select(): | |
return random.choice(range(3)) |
This file contains 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
import random | |
import datetime as dt | |
import requests | |
from pyquery import PyQuery as pq | |
s = requests.Session() | |
d = {'form_email': 'xxx', 'form_password': 'yyy'} | |
today = dt.datetime.today() | |
login_url = 'https://accounts.douban.com/login' |
This file contains 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
$ mtr -u --report -c 10 douban.com | |
Start: Sat Jan 3 09:57:13 2015 | |
HOST: diablo Loss% Snt Last Avg Best Wrst StDev | |
1.|-- 10.255.254.34 0.0% 10 0.4 0.4 0.3 0.6 0.0 | |
2.|-- 203.90.233.1 0.0% 10 1.0 1.3 0.7 4.8 1.1 | |
3.|-- 202.97.122.101 0.0% 10 4.8 3.5 1.7 5.4 1.2 | |
4.|-- 202.97.61.37 0.0% 10 39.9 39.0 37.5 40.9 0.8 | |
5.|-- 202.97.53.233 0.0% 10 38.9 39.7 38.5 40.9 0.5 | |
6.|-- 202.97.53.93 0.0% 10 37.6 39.9 37.6 42.5 1.7 | |
7.|-- ??? 100.0 10 0.0 0.0 0.0 0.0 0.0 |