Skip to content

Instantly share code, notes, and snippets.

yijia yijia2413

Block or report user

Report or block yijia2413

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View connect.txt
mysql+pymysql://root:xxxx@localhost:3306/qin?charset=utf8
View delete-none-containers-and-images.sh
#!/bin/bash
set -ex
containers=$(docker ps -a -q --filter status=exited)
if [[ ! -z ${containers} ]]; then
docker rm -f -v ${containers}
fi
@yijia2413
yijia2413 / check.sh
Created Dec 6, 2018
check bash variable is a number
View check.sh
#!/bin/bash
set -ex
if [[ "$1" =~ ^[0-9]+$ ]]; then
echo "yes"
else
echo "no"
fi
@yijia2413
yijia2413 / process_inside_container_restart.sh
Created Nov 26, 2018
Docker 内部程序crash自动重启,轻量级脚本
View process_inside_container_restart.sh
#!/bin/bash
set -ex
sleep_time=5
regex_name='server1.py'
cmd="python ${regex_name} &>> logs/test.log &"
bash -c "${cmd}"
View 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
View log.py
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 / labelencoder.py
Created Nov 7, 2018
onehot encoder & label encoder 使用
View labelencoder.py
# labelencoder 和 onehotencoder 处理测试集中未出现的样本会报错,需要进行处理
import pandas as pd
df1 = pd.read_csv("data/xxx.csv", encoding = 'utf-8', error_bad_lines=False, warn_bad_lines=False)
df1 = df1.iloc[:, :-1]
df1 = df1.drop(['xxx', 'aaa'], axis=1)
df1 = df1.fillna('0')
# 下面的代码可以直接将 整个 df labelencoder
from collections import defaultdict
d = defaultdict(LabelEncoder)
View mount.sh
#!/bin/bash
set -ex
for drive in $(ls /dev/vd* | grep -v [s-v]da); do
mount_dir=/opt/$(basename ${drive})
mkdir -p ${mount_dir}
mkfs.ext4 ${drive}
blockid=$(blkid ${drive} | cut -d "\"" -f2)
echo "UUID=${blockid} ${mount_dir} ext4 defaults 1 2" >> /etc/fstab
View c_callback_func.c
// https://segmentfault.com/a/1190000008293902
#include <stdio.h>
#include <stdlib.h>
/****************************************
* 函数指针结构体
***************************************/
typedef struct _OP {
float (*p_add)(float, float);
float (*p_sub)(float, float);
View test.py
import sys
reload(sys)
sys.setdefaultencoding('utf8')
You can’t perform that action at this time.