Skip to content

Instantly share code, notes, and snippets.

View staugur's full-sized avatar
:octocat:
Sorry, thank you!

Hiroshi.tao staugur

:octocat:
Sorry, thank you!
View GitHub Profile
@staugur
staugur / autojsonresp.py
Last active September 24, 2019 07:18
统一返回json数据,允许主动触发异常,拦截所有http异常转为json
# coding:utf8
from flask import Flask, Response, jsonify
from werkzeug.exceptions import HTTPException
class JsonResponse(Response):
@classmethod
def force_type(cls, rv, environ=None):
@staugur
staugur / Python URL Validation.py
Created September 3, 2019 08:24 — forked from Integralist/Python URL Validation.py
[Python URL Validation] #python #urls #validation
import re
ip_middle_octet = u"(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5]))"
ip_last_octet = u"(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))"
regex = re.compile(
u"^"
# protocol identifier
u"(?:(?:https?|ftp)://)"
# user:pass authentication
@staugur
staugur / pac.js
Last active May 13, 2019 06:06 — forked from hipi/pac.js
PAC
var V2Ray = "PROXY 127.0.0.1:7071; DIRECT;";
var domains = [
"graphql.cn",
"gitter.im",
"amazonaws.com",
//"raw.githubusercontent.com",
//"githubusercontent.com",
//"github.io",
//"github.com",
"gist.github.com",
@staugur
staugur / log.py
Created May 18, 2017 12:57
记录多日志文件的python代码
#!/usr/bin/python
#coding=utf-8
import logging, logging.handlers
import sys
import os
GLOBAL={"LogLevel": "WARNNING"}
class Logger:
#!/usr/bin/env python
# -*- coding: utf8 -*-
__version__ = "5.0"
__author__ = "Mr.tao"
__doc__ = "https://www.saintic.com/blog/204.html"
import re, os, sys, json, logging, requests
from multiprocessing import Pool as ProcessPool
from multiprocessing.dummy import Pool as ThreadPool
@staugur
staugur / beautiful_idiomatic_python.md
Created November 10, 2016 08:56 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@staugur
staugur / GeneratePassword.sh
Created September 21, 2016 02:17
生成复杂随机密码,复杂度可以自己修改,默认生成15个字符,可以带一个数字参数,指定生成的长度。
#!/bin/bash
#生成复杂随机密码
L=12
if [ ! -z $1 ];then
if [[ "$1" =~ ^[0-9]+$ ]];then
L=$1
fi
fi
</dev/urandom tr -dc '1234567890!@#%$qwertQWERTasdfgASDFGzxcvbZXCVBCdgFsY_lMt' | head -c${L}; echo ""
@staugur
staugur / update_nginx.sh
Created September 21, 2016 02:08
update nginx version
#!/bin/bash
v=1.8.0
nginx=/usr/local/nginx
pid=${nginx}/logs/nginx.pid
pidbin=${nginx}/logs/nginx.pid.oldbin
exec=`which nginx`
[ "$?" = "0" ] || exit 1
$exec -V &> /tmp/nginx_V
args=$(awk -F "configure arguments:" '{print $2}' /tmp/nginx_V | grep -v "^$")
echo 'If your nginx has third party modules, that is, use the "--add-module" parameter, move the module directory to the same location as the current nginx build!'
@staugur
staugur / autopush2baidu.sh
Last active September 19, 2021 18:04
向搜索引擎推送自己的URL。 1、Google Search Console是谷歌的搜索管理系统, 2、BaiduSpider
#!/bin/bash
#百度站长平台(http://zhanzhang.baidu.com/linksubmit/index)提供的主动推送(实时)接口自动提交URLs。
#要求有mailx包,开启了邮件服务
#在这里,我们用curl访问接口的方式推送一个包含所有URL列表的文件,不过需要注意的是,你推送的URL应该与百度站长平台上验证的站点一致。
#以本站为例,我在百度站长平台上添加了www.saintic.com,到网页抓取-链接提交下,看到自动提交下有个主动推送(实时),其中有你站点和token信息,看到curl推送示例,主要就是它。
#以下是我的简单推送脚本,因为百度有推送数量限制,所以放到crontab中每三个小时运行一次。
ci_dir=/tmp/baidu_ci
ci_urls=${ci_dir}/urls.txt
ci_r=${ci_dir}/ci_result.txt
@staugur
staugur / check.sh
Created September 14, 2016 08:33
Shell 入参类型预检测
检测Sdp入参,用户名是否冲突、时间期限是否符合正整数、服务|文件类型是否在范围、邮箱是否符合格式等,并将错误信息写入日志。
1).用户名若发生冲突,同个用户需要多个服务当前版本必须多次以不同用户名执行;
2).使用时间不限,至少1个月;
3).服务类型:nginx、httpd、tomcat、mysql、mongodb、redis、memcached;
4).文件类型:若为web类型可支持ftp、svn,若为app类型默认无;
5).邮件提醒:部署成功后会发给用户一封服务信息邮件(确保不在垃圾邮件中),包括服务到期、服务续费、服务停止提醒。
#判断入参及入参要求是否符合。
if [ "$#" = 5 ]; then
#判断用户是否存在