Skip to content

Instantly share code, notes, and snippets.

View saosir's full-sized avatar
♥️
Focusing

sijianliang saosir

♥️
Focusing
  • Shenzhen
View GitHub Profile
@saosir
saosir / priority_task_queue.py
Created September 15, 2022 05:20
超时优先级队列,基于python的queue包实现
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8:
# Author: Binux<[email protected]>
# http://binux.me
# Created on 2014-02-07 13:12:10
import heapq
import logging
import threading
@saosir
saosir / token_bucket.py
Last active November 1, 2022 15:47
python令牌桶实现算法
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8:
# Author: Binux<[email protected]>
# http://binux.me
# Created on 2014-02-07 16:53:08
import time
try:
import threading as _threading
@saosir
saosir / zoo.py
Created October 18, 2019 10:04
python zookeeper
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
from kazoo.client import KazooClient
from kazoo.protocol.states import KazooState
from kazoo.exceptions import ZookeeperError, NoNodeError
class ZkHelper:
@saosir
saosir / zk_cluster.sh
Created October 10, 2019 08:45
zookeeper单机集群批量部署脚本
#!/usr/bin/env sh
cd $(dirname $0)
ZK_VERSION=3.4.14
ZK_CLUSTER_NUM=3
ZK_PKG="zookeeper-"$ZK_VERSION".tar.gz"
ZK_PATH="zookeeper-"$ZK_VERSION
ZK_DATA_DIR=/tmp/zookeeper
@saosir
saosir / word2pdf.py
Created September 5, 2019 13:22
windows下 word 转 pdf
# -*- coding:utf-8 -*-
import os
import comtypes
from comtypes.client import CreateObject
wdFormatPDF = 17
in_file = os.path.abspath('f:/xx.docx')
out_file = os.path.abspath('f:/xueweizheng.pdf')
@saosir
saosir / svr.sh
Last active August 6, 2019 03:09
start/stop/restart/status shell script template for server operation
#!/bin/sh
BASE_HOME=$(dirname $(readlink -f "$0"))
PID=${BASE_HOME}/.pid
status(){
echo "==========status======="
status=`ps -p $$`
@saosir
saosir / merge_pdf_invoice.py
Created May 11, 2018 02:45
合并pdf电子发票到单个文件进行打印
import os
from PyPDF2 import PdfFileMerger
pdf_dir = r"E:\note\invoice"
def merge_pdf(source_dir, output_filename):
merger = PdfFileMerger()
for name in os.listdir(source_dir):
if ".pdf" != os.path.splitext(name)[1]:
continue
@saosir
saosir / fab_zookeeper.py
Created November 28, 2017 06:07
fabric 部署 zookeeper
#!/usr/bin/env python
# _*_ coding:utf-8 _*_
from fabric.api import run
from fabric.api import *
from fabric.contrib.files import *
from fabric.contrib.project import *
from sets import Set
from fabric.task_utils import merge
import time, os, re
# env.hosts = ['172.16.1.155','172.16.1.158']
@saosir
saosir / regex_fetch_email.py
Created April 12, 2017 10:10
正则提取文本中的邮箱地址
#!/usr/bin/env python
#
# Extracts email addresses from one or more plain text files.
#
# Notes:
# - Does not save to file (pipe the output to a file if you want it saved).
# - Does not check for duplicates (which can easily be done in the terminal).
from optparse import OptionParser
[unix_http_server]
file=/tmp/supervisor.sock ; path to your socket file
[supervisord]
logfile=/var/log/supervisord/supervisord.log ; supervisord log file
logfile_maxbytes=50MB ; maximum size of logfile before rotation
logfile_backups=10 ; number of backed up logfiles
loglevel=error ; info, debug, warn, trace
pidfile=/var/run/supervisord.pid ; pidfile location
nodaemon=false ; run supervisord as a daemon