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
@victor-perez
victor-perez / git.bat
Last active August 1, 2024 21:06
Use WSL git inside VS Code from Windows 10 17046
@echo off
setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
::this also support calls that contains a absolute windows path
::check of one of the params contain a absolute windows path
echo.%* | findstr /r /c:"[a-z]:[\\/]" > nul
if %errorlevel% == 1 (
::if not just git with the given parameters
call :git %*
@inhere
inhere / swoole-nginx.conf
Created March 7, 2018 04:00
swoole 应用的nginx配置参考
server {
listen 80;
server_name www.site.dev site.dev;
root /webroot/static;
index index.html index.htm;
error_log logs/site.dev.error.log;
access_log logs/site.dev.access.log;
##### 第一个必选规则: 匹配首页
@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
@walm
walm / main.go
Last active November 5, 2024 16:22
Simple Golang DNS Server
package main
import (
"fmt"
"log"
"strconv"
"github.com/miekg/dns"
)
@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 / 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
#判断用户是否存在
@staugur
staugur / flask_access_log.py
Last active September 14, 2016 08:26
Flask access log
#每次返回数据中,带上响应头,包含API版本和本次请求的requestId,以及允许所有域跨域访问API, 记录访问日志.
@app.after_request
def add_header(response):
response.headers["X-Version"] = __version__
response.headers["Access-Control-Allow-Origin"] = "*"
logger.info(json.dumps({
"AccessLog": {
"status_code": response.status_code,
"method": request.method,
@DarrenN
DarrenN / get-npm-package-version
Last active April 12, 2025 14:15 — forked from yvele/get-npm-package-version.sh
Extract version from package.json (NPM) using bash / shell
# Version key/value should be on his own line
PACKAGE_VERSION=$(cat package.json \
| grep version \
| head -1 \
| awk -F: '{ print $2 }' \
| sed 's/[",]//g')
echo $PACKAGE_VERSION