Skip to content

Instantly share code, notes, and snippets.

@yijia2413
yijia2413 / log.py
Last active March 21, 2019 03:30
logging
logging.basicConfig(filename=logname,
filemode='a',
format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
datefmt='%H:%M:%S',
level=logging.DEBUG)
logging.basicConfig(format='%(asctime)s,%(msecs)d %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s',
datefmt='%d-%m-%Y:%H:%M:%S',
level=logging.DEBUG)
@yijia2413
yijia2413 / shell_err.sh
Last active November 14, 2018 09:54
shell_err.sh
# https://zh-google-styleguide.readthedocs.io/en/latest/google-shell-styleguide/environment/
err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $@" >&2
}
if ! do_something; then
err "Unable to do_something"
exit "${E_DID_NOTHING}"
fi
@yijia2413
yijia2413 / process_inside_container_restart.sh
Created November 26, 2018 03:37
Docker 内部程序crash自动重启,轻量级脚本
#!/bin/bash
set -ex
sleep_time=5
regex_name='server1.py'
cmd="python ${regex_name} &>> logs/test.log &"
bash -c "${cmd}"
@yijia2413
yijia2413 / check.sh
Created December 6, 2018 01:17
check bash variable is a number
#!/bin/bash
set -ex
if [[ "$1" =~ ^[0-9]+$ ]]; then
echo "yes"
else
echo "no"
fi
#!/bin/bash
set -ex
containers=$(docker ps -a -q --filter status=exited)
if [[ ! -z ${containers} ]]; then
docker rm -f -v ${containers}
fi
@yijia2413
yijia2413 / connect.txt
Created December 27, 2018 08:47
superset 连接
mysql+pymysql://root:xxxx@localhost:3306/qin?charset=utf8
@yijia2413
yijia2413 / containerd.service
Created December 28, 2018 09:58
离线安装 Docker 和 DockeCompose
[Unit]
Description=containerd container runtime
Documentation=https://containerd.io
After=network.target
[Service]
ExecStartPre=/sbin/modprobe overlay
ExecStart=/usr/bin/docker-containerd
KillMode=process
Delegate=yes
@yijia2413
yijia2413 / mysql_connection_poll.py
Created January 7, 2019 03:23
mysql_connection_poll.py
# COPY FROM https://stackoverflow.com/questions/32658679/how-to-create-a-mysql-connection-pool-or-any-better-way-to-initialize-the-multip
#!/usr/bin/python
# -*- coding: utf-8 -*-
import time
import mysql.connector.pooling
dbconfig = {
"host":"127.0.0.1",
CREATE TABLE if not exists `test` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT,
`result` VARCHAR(128),
`update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
KEY id (id))
ENGINE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1
PARTITION BY RANGE ( TO_DAYS(update_time) ) (
-- PARTITION BY hash (TO_DAYS(update_time)) partitions 31;
PARTITION p_first VALUES LESS THAN (TO_DAYS('2019-01-07 00:00:00')),
PARTITION p20190107 VALUES LESS THAN (TO_DAYS('2019-01-08 00:00:00')),
@yijia2413
yijia2413 / list_tuples_to_string.py
Created January 11, 2019 02:52
list of tuples to string with split
a = [('a', 'etwrfb', 'casdf'), ('1', 2, '35235')]
res = '\n'.join(','.join(map(str, i)) for i in a)
# 'a,etwrfb,casdf\n1,2,35235'