Skip to content

Instantly share code, notes, and snippets.

View fanhaipeng0403's full-sized avatar
😏

Gabriel fanhaipeng0403

😏
  • 北京
View GitHub Profile
import parsedatetime
...: from time import mktime
...: from datetime import datetime
...:
...: cal = parsedatetime.Calendar()
...:
...:
...: def parse_human_time(s):
...: time_struct, _ = cal.parse(s)
...: return datetime.fromtimestamp(mktime(time_struct))
def profile(func):
def wrapper(*args, **kwargs):
import time
start = time.time()
func(*args, **kwargs)
end = time.time()
print(end - start)
from sqlalchemy import create_engine, text
from sqlalchemy.engine.url import URL
url=URL(drivername='mysql+pymysql', username='root', password="123", host="localhost",
port=3306, database="bi_dev")
engine = create_engine(url)
@fanhaipeng0403
fanhaipeng0403 / web_test.py
Created April 4, 2018 03:38 — forked from klb3713/web_test.py
用Python实现的Web服务器的压力测试脚本
# -*- coding: utf-8 -*-
__author__ = 'klb3713'
import threading, time, httplib
HOST = "127.0.0.1"; #主机地址 例如192.168.1.101
PORT = 8001 #端口
URI = "/api/huohuaId2Url" #相对地址,加参数防止缓存,否则可能会返回304
TOTAL = 0 #总数
SUCC = 0 #响应成功数
FAIL = 0 #响应失败数
@fanhaipeng0403
fanhaipeng0403 / upsert.py
Created December 19, 2018 13:47 — forked from timtadh/upsert.py
How to compile an INSERT ... ON DUPLICATE KEY UPDATE with SQL Alchemy with support for a bulk insert.
#!/usr/bin/env python
# Copyright (c) 2012, Tim Henderson
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
@fanhaipeng0403
fanhaipeng0403 / channel.md
Created January 13, 2020 14:38 — forked from xin053/channel.md
[go channel] go channel #go #channel

channel 重点

Operation A Nil Channel A Closed Channel A Not-Closed Non-Nil Channel
Close panic panic succeed to close (C)
Send Value To block for ever panic block or succeed to send (B)
Receive Value From block for ever never block (D) block or succeed to receive (A)

一个基于无缓存 channel 的发送操作将导致发送者 goroutine 阻塞, 直到另一个 goroutine 在相同的 channel 上执行接收操作, 当发送的值通过 channel 成功传输之后, 两个 goroutine 可以继续执行后面的语句, 反之,如果接收操作先发生, 那么接收者 goroutine 也将阻塞, 直到有另一个 goroutine 在相同的 channel 上执行发送操作