Skip to content

Instantly share code, notes, and snippets.

@suzaku
suzaku / clean_movies.js
Created May 2, 2014 23:34
豆瓣电影首页[正在热映]中去掉分数低于7的条目
(function () {
var hot_movies = document.querySelectorAll('.ui-slide-item');
[].forEach.call(
hot_movies,
function (e) {
var rate = e.getAttribute('data-rate');
rate = parseInt(rate, 10);
if (!isNaN(rate) && rate < 7) {
e.remove();
}
[etcd] Jul 31 03:41:53.475 INFO | 20634ec121f9479ca7a6cd50a5efcc0b: warning: heartbeat time out peer="86a6adecb8c
[etcd] Jul 31 03:42:24.976 INFO | 20634ec121f9479ca7a6cd50a5efcc0b: warning: heartbeat time out peer="86a6adecb8c
[etcd] Jul 31 03:44:00.477 INFO | 20634ec121f9479ca7a6cd50a5efcc0b: warning: heartbeat time out peer="86a6adecb8c
[etcd] Jul 31 03:44:32.225 INFO | 20634ec121f9479ca7a6cd50a5efcc0b: warning: heartbeat time out peer="86a6adecb8c
[etcd] Jul 31 03:45:36.475 INFO | 20634ec121f9479ca7a6cd50a5efcc0b: warning: heartbeat time out peer="86a6adecb8c
[etcd] Jul 31 03:46:10.975 INFO | 20634ec121f9479ca7a6cd50a5efcc0b: warning: heartbeat time out peer="86a6adecb8c
[etcd] Jul 31 03:46:43.976 INFO | 20634ec121f9479ca7a6cd50a5efcc0b: warning: heartbeat time out peer="86a6adecb8c
[etcd] Jul 31 03:47:12.563 INFO | 20634ec121f9479ca7a6cd50a5efcc0b: warning: heartbeat time out peer="86a6adecb8c
[etcd] Jul 31 03:47:16.475 INFO | 20634ec121f9479ca7a6cd50a5efcc0b:
@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
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: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))
s = "s = {:c}{}{:c}{:c}print(s.format(34, s, 34, 10))"
print(s.format(34, s, 34, 10))
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
@suzaku
suzaku / R1Page.md
Created September 25, 2012 06:07
Model Thinking Note
  • In confronting complex situations, no single model can capture everything. Thus, we need to bring several of models to bear, not just one

  • as powerful as models may be, they’re only guides to thinking. We have to maintain contact with reality.

@suzaku
suzaku / gist:3786423
Created September 26, 2012 06:25
About Graph
  • Simple Graph

  • Undirected

  • has no loops

  • no more than one edge between any two different vertices

  • Regular Graph

    • each vertex has the same number of neighbors
  • Complete Graph

  • each pair of vertices has an edge connecting them

  • different functions with the same growth rate may be represented using the same O notation.
  • If f(x) is a sum of several terms, the one with the largest growth rate is kept, and all others omitted.
  • If f(x) is a product of several factors, any constants (terms in the product that do not depend on x) are omitted.