Skip to content

Instantly share code, notes, and snippets.

@BroHui
BroHui / ipset_wrapper.py
Created May 24, 2016 08:04
ipset python 包装
#!/bin/env python
import subprocess
import logging
fmt = "%(asctime)-15s %(levelname)s %(filename)s %(lineno)d %(process)d %(message)s"
datefmt = "%a %d %b %Y %H:%M:%S"
logging.basicConfig(format=fmt, datefmt=datefmt, level=logging.INFO)
def ipset_basic_struct(action, ipset_name, ip):
@BroHui
BroHui / demo.py
Last active May 31, 2016 09:57
Headless Chrome via Xvfb & selenium
from pyvirtualdisplay import Display
from selenium import webdriver
import os
display = Display(visible=0, size=(1024, 768))
# display port ,exmaple :1001
displayport = display.display
os.environ["DISPLAY"] = displayport
display.start()
@BroHui
BroHui / sample.html
Created August 30, 2017 06:15
表格内容过长自动省略CSS模版
<td class="autocut">
@BroHui
BroHui / remove_comments.py
Created September 13, 2017 03:31
Remove comments and docstrings from a python fille.
""" Strip comments and docstrings from a file.
"""
import sys, token, tokenize
def do_file(fname):
""" Run on just one file.
"""
source = open(fname)
# -*- coding: utf-8 -*-
import gevent.monkey
gevent.monkey.patch_all()
import collections
import threading
import time
import random
import sys
@BroHui
BroHui / async-socket.py
Created March 7, 2018 01:24 — forked from lkraider/async-socket.py
Example of using gevent for async socket server and client
import gevent
import gevent.server
import gevent.monkey
gevent.monkey.patch_all()
import socket
import string
import random
import filecmp
@BroHui
BroHui / Dockerfile
Last active May 11, 2021 01:11
Django2.2 ship on Docker with uwsgi
FROM python:3.7.9-slim-buster as base
WORKDIR /wheels
COPY ./requirements.txt .
RUN apt-get update && \
apt-get install -y \
default-libmysqlclient-dev \
libmariadb3 \
gcc
RUN pip install -U pip \
&& pip install --no-cache-dir wheel \
@BroHui
BroHui / Dockerfile
Last active September 28, 2023 02:28
Django 1.11 LTS ship on Docker with uwsgi
FROM python:2.7.18-slim-stretch as base
WORKDIR /wheels
COPY ./requirements.txt .
RUN apt-get update && \
apt-get install -y \
default-libmysqlclient-dev \
libmariadbclient18 \
gcc
RUN pip install -U pip \
&& pip install --no-cache-dir wheel \
@BroHui
BroHui / vcode_gen.py
Created December 4, 2020 02:48
Python生成验证码方案
# coding: utf-8
"""
Python 验证码生成封装
生产环境使用NO POLT模式,单次耗时100ms左右。
2020-12-04
"""
from captcha.image import ImageCaptcha
@BroHui
BroHui / django2.2.spec
Created January 12, 2021 09:14
Django2.2 PyInstaller For Win10
# -*- mode: python -*-
block_cipher = None
a = Analysis(['myproject\\manage.py'],
pathex=['D:\\GitHub\\django_samples\\django_pyinstaller_sample'],
binaries=[],
datas=[
('myproject/templates', 'templates'),