Skip to content

Instantly share code, notes, and snippets.

View buaawp's full-sized avatar

Peng Wang buaawp

View GitHub Profile
@buaawp
buaawp / RobotFramework-ExcelLibrary.py
Last active April 14, 2016 10:08
A robot framework library for reading data from excel file
#coding=utf-8
import xlrd
class ExcelLibrary():
def open_excel_sheet(self,filename,sheetname="Sheet1"):
bk=xlrd.open_workbook(filename)
table=bk.sheet_by_name(sheetname)
return table
@buaawp
buaawp / extendXMLHttpRequest.js
Created April 12, 2016 03:10
修改XMLHttpRequest发送方法,更改Ajax目标url。(不支持跨域)
/**
* 修改XMLHttpRequest发送方法,更改Ajax目标url
*/
XMLHttpRequest.prototype._open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url, async) {
// 用对象便于修改参数
var options = {
method: method,
url: url,
async: async
@buaawp
buaawp / extendJQueryAjax.js
Last active April 12, 2016 03:12
扩展Ajax方法,重写url / 实现jsonp / 处理响应数据(可支持跨域)
(function($){
//备份jquery的ajax方法
var _ajax=$.ajax;
//重写jquery的ajax方法
$.ajax=function(opt){
//opt.jsonp = 'callbackparam';
//opt.jsonpCallback="printMockLog";
//opt.dataType = 'jsonp';
//opt.url='http://127.0.0.1:8000/myjsonp/getPumsData?url='+opt.url;
@buaawp
buaawp / socketserver.py
Created April 7, 2016 11:28
python socket server , 用于端口监听
#usage http://auto.58corp.com:9011/
if __name__ == '__main__':
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('', 9011))
sock.listen(5)
while True:
connection,address = sock.accept()
try:
connection.settimeout(5)
@buaawp
buaawp / opencv_demo.py
Created March 29, 2016 02:37
使用opencv进行图像验证
#decoding:utf-8
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import time
import cv2.cv as cv
browser = webdriver.Firefox() # Get local session of firefox
browser.get("http://www.baidu.com") # Load page
@buaawp
buaawp / select2-usage.js
Last active March 29, 2016 02:35
select2 使用
//触发onchange事件
$('#my_id').val('3').trigger('change');
//动态添加元素后重新初始化列表
$(tr).find('.select-source').next().remove();
$(tr).find('.select-source').select2({
minimumResultsForSearch: Infinity
});
@buaawp
buaawp / js_input_number_only.js
Last active March 25, 2016 04:10
js限定input只能输入数字
//只能输入数字
$(document).on('keypress','input[type=number]',function(e){
var e = e || window.event;
if (e.keyCode >= 48 && e.keyCode <= 57)
{
e.returnValue = true;
} else {
e.preventDefault();
}
});