Skip to content

Instantly share code, notes, and snippets.

@yijia2413
yijia2413 / getip.sh
Created May 28, 2020 01:54
get ip address
#!/bin/bash
set -ex
ip route get 8.8.8.8 | head -1 | awk '{print $7}'
@yijia2413
yijia2413 / csvlogger.py
Created May 7, 2020 02:13
set up csv logger in python
import logging
def setup_csv_logger(log_file, name='csv', level=logging.INFO):
handler = logging.FileHandler(log_file)
handler.setFormatter(
logging.Formatter('%(asctime)s,%(message)s',
datefmt='%Y-%m-%d:%H:%M:%S')
)
csvlogger = logging.getLogger(name)
csvlogger.setLevel(level)
@yijia2413
yijia2413 / docker-commands.md
Created June 24, 2019 07:03
Docker commands

delete volumes not in use

docker volume rm $(docker volume ls -qf dangling=true)
@yijia2413
yijia2413 / options.sh
Created May 9, 2019 09:50
shell options
# copy from https://coolshell.cn/articles/8619.html
#!/bin/bash
# Bash Menu Script Example
PS3='Please enter your choice: '
options=("Option 1" "Option 2" "Option 3" "Quit")
select opt in "${options[@]}"
do
case $opt in
@yijia2413
yijia2413 / insert.sh
Created April 22, 2019 08:48
MySQL insert duplicate key
insert into proc_runtime (vm, procname) values ('100', 'wechat.exe') on duplicate key update vm = values(vm), procname = values(procname), day_runtime =day_runtime + values(day_runtime)
@yijia2413
yijia2413 / README.md
Last active March 4, 2019 11:25
K8S Config

Config Ingress Nginx

  • mandatory.yml, do not use hostNetwork, # hostNetwork: true
  • cloud-generic.yml, add externalIPs
    kind: Service
    apiVersion: v1
    metadata:
      name: ingress-nginx
      namespace: ingress-nginx
      labels:
    
@yijia2413
yijia2413 / k8s_op.sh
Last active October 31, 2019 09:40
k8s operations
# start proxy allow remote access
kubectl proxy --address=0.0.0.0 --port=80 --accept-hosts='^*$'
# port forward
kubectl --address 0.0.0.0 port-forward redis-test1-xxxx 6379:6379
# check pod startup issue
kubectl describe pod [my-pod-name] -n [kube-system](namespace)
# show all pods
@yijia2413
yijia2413 / tz.sh
Last active April 19, 2019 01:59
chang timezone
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# for linux
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# for alpine
RUN apk add --no-cache tzdata
ENV TZ Asia/Shanghai
@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'
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')),