Skip to content

Instantly share code, notes, and snippets.

@yiidtw
yiidtw / unzip.spec
Created May 23, 2018 06:17
unzip.spec example for writing RPM building tutorial
Summary: A utility for unpacking zip files
Name: unzip
Version: 6.0
Release: 20%{?dist}
License: BSD
Group: Applications/Archiving
Source: http://downloads.sourceforge.net/infozip/unzip60.tar.gz
# Not sent to upstream.
Patch1: unzip-6.0-bzip2-configure.patch
# Upstream plans to do this in zip (hopefully also in unzip).
@yiidtw
yiidtw / CICD Pipeline under Microservices for Developer
Created June 12, 2018 08:45
UML description for webwequencediagrams
title CI/CD Pipeline under Microservices for Developer\n@ yiidtw.github.io/blog
participant RD
participant Git
participant Jenkins
participant Harbor
participant Kubernetes
Git->RD: fork to personal repo
note over RD: develop & \nUNIT TEST
@yiidtw
yiidtw / cpu_test.py
Created September 9, 2018 14:35
generate CPU loading with 5 sec and close it in python 2.7
# -*- coding: utf-8 -*-
import threading, sys, time
from math import pi
def workload(stop_event, arg):
# while not stop_event.wait(1):
# print ("working on %s" % arg)
while not stop_event.is_set():
pi * pi
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yiidtw
yiidtw / python-flask.service
Created November 13, 2018 06:34
example of a systemd service file running a python + flask + gunicorn application
[Unit]
Description=Gunicorn instance to serve python-flask
After=network.target
[Service]
User=centos
Group=centos
WorkingDirectory=/home/centos/python-flask
Environment="PATH=/home/centos/miniconda2/envs/python-flask/bin"
ExecStart=/home/centos/miniconda2/envs/python-flask/bin/gunicorn --bind 0.0.0.0:8000 wsgi
@yiidtw
yiidtw / logit.py
Created December 19, 2018 11:00
Simple log function for python 3
from datetime import datetime
def logit(msg, log_type="INFO"):
try:
print(' {} {} {}'.format(log_type, datetime.now().strftime("%Y-%m-%d %H:%M:%S"), msg))
except Exception as e:
print(' ERROR logging' + e.message)
@yiidtw
yiidtw / snippet.sh
Last active February 9, 2019 16:07
useful snippet for shell script
# sed
sed -i "s/old/new/g" /path/to/file
# find
find . -name "*.log" -type f | while read f; do echo $f; done
# fine and delete
find . -name "*.pyc" -exec rm -f {} \;
# compress a dir and scp
@yiidtw
yiidtw / setup-ntpd.sh
Last active February 16, 2019 17:44
install and configure ntpd on centos7
# http://www.stdtime.gov.tw/chinese/bulletin/NTP%20promo.txt
sudo yum install -y ntp
sudo sed -i "s/server 0.centos.pool.ntp.org iburst/server time.stdtime.gov.tw prefer/g" /etc/ntp.conf
sudo sed -i "s/server 1.centos.pool.ntp.org iburst/server tick.stdtime.gov.tw/g" /etc/ntp.conf
sudo sed -i "s/server 2.centos.pool.ntp.org iburst/server tock.stdtime.gov.tw/g" /etc/ntp.conf
sudo sed -i "s/server 3.centos.pool.ntp.org iburst/server clock.stdtime.gov.tw/g" /etc/ntp.conf
sudo ntpdate time.stdtime.gov.tw # must nptdate before ntpd start, otherwise the port would be occupied by ntpd
sudo systemctl start ntpd && sudo systemctl enable ntpd
@yiidtw
yiidtw / setup-virtualenv.sh
Created January 13, 2019 10:47
setup up python3 virtualenv on centos7
sudo yum install -y epel-release
sudo yum install -y python-pip python-virtualenv python-virtualenvwrapper
cat <<EOF >>$HOME/.bashrc
if [ -f /usr/bin/virtualenvwrapper.sh ]; then
export WORKON_HOME=~/.virtualenvs
source /usr/bin/virtualenvwrapper.sh
fi
EOF