Skip to content

Instantly share code, notes, and snippets.

View borgle's full-sized avatar

波哥 borgle

View GitHub Profile
@borgle
borgle / gist:c846d07cdaa70933fd30
Created November 12, 2013 02:55
我的python html抓取代码。 data为一个dict值,是需要post的数据字典。
#!/usr/bin/python
# -*- coding: utf-8 -*-
import socket,urllib,time,urllib2
import re,StringIO,gzip
def gethtml(pageurl, data=None):
theheaders = {
'User-agent' : 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko)',
'Accept-Encoding' : 'gzip, deflate',
@borgle
borgle / upgrade_filetime.py
Created January 15, 2016 01:54
有时候需要更改当前目录下所有文件的访问时间和修改时间,当文件过多的时候,可以试试这个小脚本。当然,如果你是工作在linux上,这个可以帮助到你【 find ./ | xargs touch -c -t 201601010000 】
#!/usr/bin/env python
# -*- coding:utf8 -*-
import time,os,sys
newtime = time.time()
for root,dirs,files in os.walk(os.path.dirname(__file__)):
for name in files:
filepath = os.path.join(root, name)
os.utime(filepath, (newtime,newtime))
sys.stdout.write(u"\r正在处理 %s...%s" % (filepath.decode('gbk')[:35-len(name)],filepath.decode('gbk')[-len(name)-35:]))
@borgle
borgle / GridViewSort.cs
Created February 18, 2016 17:08 — forked from sayurin/GridViewSort.cs
Automatically sort library for WPF ListView (GridView).
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
namespace Sayuri.Windows {
public static class GridViewSort {
class SortIcon : Adorner {
@borgle
borgle / hzti.com.9004.py
Created March 13, 2016 09:13
杭州市机动车驾驶人考试互联网预约平台预约考试人员统计脚本
#coding: utf-8
import requests,re
headers = {'User-Agent': 'Mozilla/4.0',
'Accept-Language':'en-US,en;q=0.8',
'Accept-Encoding':'gzip, deflate, sdch',
'Cache-Control': 'max-age=0',
'Accept': 'text/html;q=0.9,*/*;q=0.8'
}
@borgle
borgle / Hello.py
Last active July 4, 2016 10:53
simplify Web Server base on wsgi on gunicorn, gevent. visit eg. http://localhost/DEMO/Hello?method=Say&other=otherparameter
#!/usr/bin/env python
# coding:utf-8
import requsts
import imghdr, json
''' this file is in package DEMO folder '''
def Say(parameters, start_response):
s = {
@borgle
borgle / google.reverse.conf
Last active July 21, 2016 02:36
集合多人智慧,nginx反向代理google网站的配置。 如果是restart nginx的话,记得先rm -rf /var/run/nginx-gunzip.sock;当然reload的话,就不需要。
upstream google {
server 210.158.146.160:443 max_fails=3;
server 210.158.146.161:443 max_fails=3;
server 210.158.146.162:443 max_fails=3;
server 210.158.146.163:443 max_fails=3;
server 210.158.146.164:443 max_fails=3;
server 210.158.146.165:443 max_fails=3;
# add more google ip
}
server {
@borgle
borgle / relation.txt
Created August 31, 2016 06:38
relation
     祖 祖                       外   外
                               祖   祖
     母 父                       父   母
     │ │                       │   │
     └┬┘                       └─┬─┘
┌───┬─┴─┬──────────┐       ┌─────┴───┬───┐
│   │   │          │       │         │   │
姑 姑 嬸 叔 伯 伯        父       母         舅 舅 姨 姨
丈 媽 嬸 父 母 父        親       親         舅 媽 媽 丈
@borgle
borgle / random_example.py
Created March 14, 2017 02:42
Python 随机大集合,要善于利用 string 里面的常量(ascii_letters, ascii_lowercase, ascii_uppercase, letters, digits, hexdigits, octdigits),减少代码量。
import random, string
# number
number = random.randint(1, 9)
# char
char = chr(random.randint(65, 90))
char = random.choice(string.ascii_letters)
# string
@borgle
borgle / install.sh
Created March 15, 2017 09:06
很多时候,团队内每个人都需要测试环境,如果大家都在测试环境上随意捣鼓,那么tomcat, mongodb, redis, zookeeper将是一团麻,这个脚本就是方便大家进行环境初始化和测试的
#!/bin/bash
# global variable
SVR_PORT=0
RUN_USER=$USER
BIN_DIR=$HOME/bin
# resolve links - $0 may be a softlink
ARG0="$0"
while [ -h "$ARG0" ]; do
@borgle
borgle / crawler.py
Created March 17, 2017 18:29
一个最基本的多线程抓取页面代码
#coding: utf-8
import struct
import requests,json,random
from gevent import monkey, spawn
monkey.patch_all()
proxies = {'all': 'http://127.0.0.1:8087'}
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/168 Safari/537.36',