Skip to content

Instantly share code, notes, and snippets.

View klb3713's full-sized avatar

取梦为饮 klb3713

  • Beijing China
View GitHub Profile
@klb3713
klb3713 / cluster
Created July 5, 2014 05:59 — forked from jdeng/cluster
// generate [0..n-1]
auto seq = [](size_t n) -> std::vector<size_t> {
std::vector<size_t> v(n);
for (size_t i=0; i<n; ++i) v[i] = i;
return v;
};
auto index = seq(n);
// n * n distance matrix
std::vector<D> dists(n * n);
@klb3713
klb3713 / regexp.c
Created April 30, 2014 12:30
参考《代码之美》写的一个实现了. * + c ^ $六种常用语法的正则匹配器
/*
* =====================================================================================
*
* Filename: regexp.c
*
* Description: 参考《代码之美》写的一个实现了. * + c ^ $六种常用语法的正则匹配器
*
* Version: 1.0
* Created: 2014-4-30
* Revision: none
import theano
import theano.tensor as T
import numpy as np
import cPickle as pickle
#theano.config.compute_test_value = 'warn'
class Meta(object):
def __init__(self):
@klb3713
klb3713 / valid_xml.py
Created August 24, 2013 07:21
lxml: 使用xsd验证xml文件
# -*- coding: utf-8 -*-
__author__ = 'klb3713'
from lxml import etree
xsdfile = etree.parse("./test.xsd")
xmlschema = etree.XMLSchema(xsdfile)
xmldoc = etree.parse("./test.xml")
print xmlschema.validate(xmldoc)
@klb3713
klb3713 / crawl_youku.py
Last active December 20, 2015 22:59
python 爬取优酷视频信息,并存储到mongodb
# -*- coding: utf-8 -*-
__author__ = 'klb3713'
import re
import json
import urllib2
from lxml import etree
from multiprocessing import Process
from pymongo import Connection
@klb3713
klb3713 / timer.py
Last active December 20, 2015 22:29
Python 定时器:在定时执行这些操作的时候,我们并不想影响主程序的正常进行,所以我们继承了线程类,有2个标记符,这两个标记符用来保证程序退出时候能够正常退出(执行完毕才退出,而不是直接退出),另外lastDo这个标记符用来申明当定时器收到结束命令的时候是否最后执行一次程序,以保证数据的完整。
import threading,time
class Timer(threading.Thread):
def __init__(self,fn,args=(),sleep=0,lastDo=True):
threading.Thread.__init__(self)
self.fn = fn
self.args = args
self.sleep = sleep
self.lastDo = lastDo
self.setDaemon(True)
@klb3713
klb3713 / web_test.py
Created July 25, 2013 06:07
用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 #响应失败数
@klb3713
klb3713 / getSelect_clearSelect.js
Created June 27, 2013 13:59
Javascript获取选中的html和取消选择状态代码,兼容IE、Chrome和FF
function getSelectionHtml() {
var html = "";
if (typeof window.getSelection != "undefined") {
var sel = window.getSelection();
if (sel.rangeCount) {
var container = document.createElement("div");
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
html = container.innerHTML;