Skip to content

Instantly share code, notes, and snippets.

View AntiKnot's full-sized avatar
🎯
Focusing

Yan.xxx AntiKnot

🎯
Focusing
View GitHub Profile
@AntiKnot
AntiKnot / foo.py
Created April 2, 2020 07:26
python signal blinker
from blinker import signal
def subscriber(sender):
print("Got a signal send by %r" % sender)
# already have signal, define own receive method
send_data = signal('send-data')
@AntiKnot
AntiKnot / foo.py
Created April 2, 2020 07:30
接上 signal 信号模式的基本结构
def my_callback(sender, **kwargs):
'''
这是个receiver函数
'''
print(sender)
print(kwargs)
print("Request finished!")
class Observed(object):
@AntiKnot
AntiKnot / oss.py
Last active April 8, 2020 06:23
aliyun oss upload & download file
# -*- coding: utf-8 -*-
import os
import oss2
oss_accesskeyid = os.environ.get('OSS_AccessKeyId', None)
oss_accesskeysecret = os.environ.get('OSS_AccessKeySecret', None)
oss_endpoint = os.environ.get('OSS_ENDPOINT', None)
oss_bucketname = os.environ.get('OSS_BUCKETNAME', None)
# 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://ram.console.aliyun.com 创建RAM账号。
version: '2'
services:
dnsmasq:
image: andyshinn/dnsmasq:latest
restart: always
ports:
- "53535:53/tcp"
- "53535:53/udp"
cap_add:
- NET_ADMIN
@AntiKnot
AntiKnot / mySort.py
Created April 29, 2020 17:26
python sort; python内置排序
l1 = [1, 2, 3]
l2 = list.sort(l1)
l3 = l1.sort()
l4 = sorted(l1)
def myprint(l):
print("{}, id:{}".format(l, id(l)))
return 0
@AntiKnot
AntiKnot / validate.py
Last active May 12, 2020 01:57
Validator will not pass extra kv in dict
from cerberus import Validator
schema = {'a': {'type': 'string'}}
data = {'a': '1', 'b': None}
if __name__ == '__main__':
v = Validator()
if not v.validate(data, schema):
print(v.errors)
@AntiKnot
AntiKnot / Dockerfile
Created May 28, 2020 04:07
Test whether services in multiple docker-compose files establish network links and can be accessed by container name
FROM python:3.6
WORKDIR /Project/demo
COPY requirements.txt ./
RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
COPY . .
CMD ["python", "app.py"]
@AntiKnot
AntiKnot / docker-compose.yml
Last active May 29, 2020 05:20
docker-compose mongo replica set
version: '2'
services:
# MONGODB
mongo:
image: mongo:4.2
# hostname: mongo.myrepl
networks:
- mset
command:
@AntiKnot
AntiKnot / Makefile
Last active June 1, 2020 06:14
linux kernel 101
obj-m += hello.o
PWD := $(shell pwd)
KVER := $(shell uname -r)
KDIR :=/lib/modules/$(KVER)/build/
all:
$(MAKE) -C $(KDIR) M=$(PWD)
clean:
rm -rf *.o *.mod.c *.mod.o *.ko *.symvers *.order *.a
@AntiKnot
AntiKnot / cm.py
Last active June 1, 2020 10:17
python ChainMap new_child parents
from collections import ChainMap
d1 = {'a': 'a', 'b': 'b'}
d2 = {'c': 'c', 'd': 'd'}
m = ChainMap(d1, d2)
if __name__ == '__main__':
print(m)
n = m.new_child({"e": "e"})