Skip to content

Instantly share code, notes, and snippets.

import pika
class RabbitMQ(object):
def __init__(self, host, port=5672):
self.host = host
self.port = port
self.conn = ""
self.channel = ""
@olivetree123
olivetree123 / upgrade.sh
Created August 28, 2018 05:36
Ubuntu 14.04 升级
apt-get update && apt-get dist-upgrade
reboot
do-release-upgrade
# 修改 /etc/apt/sources.list 为 Ubuntu 16.04 的源
do-release-upgrade
@olivetree123
olivetree123 / alpine37.conf
Created June 23, 2018 03:22
alpine3.7 添加阿里云源
# alpine3.7 添加阿里云源
RUN echo 'http://mirrors.aliyun.com/alpine/v3.7/main/' > /etc/apk/repositories \
&& echo 'http://mirrors.aliyun.com/alpine/v3.7/community/' >> /etc/apk/repositories
"""
python sqlite3 使用
"""
class AliceDB(object):
def __enter__(self):
self._connect()
return self
def __exit__(self, type, value, trace):
@olivetree123
olivetree123 / log.py
Created May 29, 2018 07:35
记录日志
#coding:utf-8
import logging
# mylogger 可以在日志中显示 %(name)s,这样就可以看出是哪个logger 打出的日志。没啥用。
# 默认为 root logger
logger = logging.getLogger("mylogger")
logger.setLevel(logging.DEBUG)
@olivetree123
olivetree123 / https.sh
Last active April 26, 2018 12:35
配置 HTTPS
openssl genrsa -des3 -out ca.key 2048
openssl req -new -x509 -days 7305 -key ca.key -out ca.crt
openssl genrsa -des3 -out blog.creke.net.pem 2048
openssl req -new -nodes -sha256 -newkey rsa:2048 -keyout blog.creke.net.key -out blog.creke.net.csr
openssl ca -policy policy_anything -days 1460 -cert ca.crt -keyfile ca.key -in blog.creke.net.csr -out blog.creke.net.crt
# 如果出现找不到文件夹的错误,执行以下步骤
mkdir -p CA/newcerts
touch CA/index.txt
touch CA/serial
@olivetree123
olivetree123 / str_vs_bytes.py
Last active April 26, 2018 01:30
字符串和字节串
# Python3 最重要的新特性大概要算是对文本和二进制数据作了更为清晰的区分。
# 文本总是Unicode,由str类型表示,二进制数据则由bytes类型表示。
# Python3 不会以任意隐式的方式混用str和bytes,正是这使得两者的区分特别清晰。
# 你不能拼接字符串和字节包,也无法在字节包里搜索字符串(反之亦然)
b = b"example" # bytes object
s = "example" # str object
bytes(s, encoding = "utf8") # str to bytes
str(b, encoding = "utf-8") # bytes to str
@olivetree123
olivetree123 / upload_client.py
Last active April 25, 2018 01:26
requests 上传文件
import requests
files = {'file': open('/Users/gao/nixiongwo.png', 'rb')}
data = {"name":"123", "info":"hahaha"}
r = requests.post("http://www.baidu.com/postfile", files=files, data=data)
# 更多参数格式参考:https://blog.csdn.net/five3/article/details/74913742
@olivetree123
olivetree123 / source.list
Last active April 18, 2018 04:00 — forked from yzf/ubuntu_16.04_ali.list
ubuntu 16.04 阿里云源
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
@olivetree123
olivetree123 / utils.py
Last active November 5, 2018 06:45
通用函数
#coding:utf-8
import hashlib
from datetime import datetime
UTC_DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
def file_md5(f):
hash_md5 = hashlib.md5()
for chunk in iter(lambda: f.read(4096), b""):