Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
import requests
import re
from lxml import etree
import genanki
import tempfile
import sys
import os
import io
package main
import (
"bytes"
"flag"
"fmt"
"io"
"log"
"net/http"
"net/url"
#!/bin/sh
ver=$1
plat=$(uname -s)
plat=${plat,,}
arch=$(uname -m)
arch=${arch,,}
case $arch in
"i686")
arch="386"
;;
@emptyhua
emptyhua / gist:7151798
Created October 25, 2013 09:03
subprocess readline
import subprocess
ping = subprocess.Popen(['ping', 'www.taobao.com'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
for line in iter(ping.stdout.readline, ''):
print line
@emptyhua
emptyhua / gist:6111449
Created July 30, 2013 09:09
压力测试神马的
var Wget = require('./http_request.js').HttpRequest;
var total = 0;
var fail = 0;
setInterval(function() {
console.log(total + 'qps');
console.log(fail + 'failed');
total = 0;
fail = 0;
@emptyhua
emptyhua / gist:5079839
Created March 4, 2013 04:07
PHP中注册退出hook
function memcache_lock_clean() {
global $memcache_locks;
$mem = require_memcache();
foreach($memcache_locks as $key=>$v){
$mem->delete('LOCK' . $key);
}
}
register_shutdown_function('memcache_lock_clean');
@emptyhua
emptyhua / gist:5055043
Last active December 14, 2015 08:08
PHP日志打印
function debug_log() {
if (false) return; //开关
static $fp = 0;
if ($fp === 0) {
$logname = 'myprojectname';//日志名称
$fp = fopen('/tmp/' . $logname . '.debug.log', 'a');
}
$traces = debug_backtrace();
$trace = count($traces) > 1 ? $traces[1] : $traces[0];
$log_msg = date('Y-m-d H:i:s') . ' FILE:' . basename($trace['file']) . ' FUNC:' . $trace['function'] . ' LINE:' . $trace['line'] . ' :' . "\n";