Skip to content

Instantly share code, notes, and snippets.

class MyMeta(type):
def __new__(cls, name, bases, dct):
print "meta: creating %s %s" % (name, bases)
for pkls in bases:
for key, value in pkls.__dict__.items():
if isinstance(value, Field):
pass
#print name,value
#setattr(kls, key, value)
kls = type.__new__(cls, name, bases, dct)
@allenyang79
allenyang79 / re-raise-2.py
Created June 14, 2019 03:48
python 2.7 re-raise
exc_type, exc_val, tb = sys.exc_info()
raise CustomError("oops," +str(e), ["AAA", "BBB"]), None, tb
# vi: set ts=2 sw=2:
version: '3.4'
services:
rabbitmq:
image: rabbitmq:3.7-management
volumes:
- ./rabbitmq:/var/lib/rabbitmq
ports:
- 5672:5672
- 15672:15672
"""
python3有concurrent.futures新功能可以做JobQueuePool的機制
"""
import concurrent.futures
import requests # This is not standard library
URLS = [
'https://docs.python.org/3/library/ast.html',
'https://docs.python.org/3/library/abc.html',
'https://docs.python.org/3/library/time.html',
@allenyang79
allenyang79 / one.py
Created March 12, 2019 07:06
keep only one process can run at the same time
import os
import atexit
def keep_single_process():
pid = str(os.getpid())
pidfile = "/tmp/main_coupang.pid"
if os.path.isfile(pidfile):
raise Exception("%s already exists, exiting" % pidfile)
with open(pidfile, 'w') as fp:
@allenyang79
allenyang79 / get-chunk.py
Created March 8, 2019 02:46
a easy way to gen pre-split key
import math
def _get_chunks(chunk_size=4, chars=None):
if not chars:
# chars = list('0123456789') # list('-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz')
chars = list('-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz')
m = chars_size = len(chars)
output_size = 1
while m < chunk_size:
@allenyang79
allenyang79 / job-queue.py
Created March 7, 2019 05:59
python threading job-queue
import multiprocessing as mp
import time
import random
import traceback
import threading
import Queue
import os
import logging
@allenyang79
allenyang79 / config-yaml.py
Created August 15, 2018 05:56
use yaml as config, 似乎不是很理想
import yaml
import configparser
# print(dir(yaml))
data = yaml.load("""
a:
a1: a1
a2: a2
a3: "%(a1)s-%(a2)s"
b:
b1: b1
from jboss/keycloak:4.1.0.Final
USER root
RUN yum install -y iproute
USER jboss
COPY docker-entrypoint.sh docker-entrypoint.sh
COPY srv/jdbc-ping.cli /srv/jdbc-ping.cli
# COPY jdbc-ping.sh keycloak/bin/jdbc-ping.sh
import csv
with open(file) as fp:
reader = csv.DictReader(fp, delimiter=',', lineterminator="\r\n",quotechar='"')
for row in reader:
src_data.append(row)