Skip to content

Instantly share code, notes, and snippets.

# -*- coding:utf-8 -*-
import time
import logging
import string
import random
import hmac
import base64
import hashlib
import requests
from collections import deque
def flatten(list_):
return list(iflatten(list_))
def iflatten(list_):
seen = set()
list_ = deque(list_)
@suzaku
suzaku / main.go
Last active March 7, 2016 08:41
Command line tool for saving a simple image to the specified path
package main
import (
"fmt"
"image"
"image/color"
"image/draw"
"image/jpeg"
"image/png"
"log"
@suzaku
suzaku / create_image.go
Created March 7, 2016 08:21
A function that fill an image with specified background color
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
}
import sys
class Stupid(Exception):
pass
class X:
def __getattr__(self, name):
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
s = "s = {:c}{}{:c}{:c}print(s.format(34, s, 34, 10))"
print(s.format(34, s, 34, 10))
@suzaku
suzaku / gist:8be8250980e9da7e18cf
Created May 26, 2015 08:15
Simulation of the Monty Hall problem
import random
def setup_doors():
doors = [0] * 3
doors[random.choice(range(3))] = 1
return doors
def select():
return random.choice(range(3))
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'
@suzaku
suzaku / gist:76c8f47b52e5229e56d7
Created January 3, 2015 01:58
`mtr -u --report -c 10 douban.com` from HK
$ 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