Skip to content

Instantly share code, notes, and snippets.

View justdoit0823's full-sized avatar

余森彬 justdoit0823

View GitHub Profile
@justdoit0823
justdoit0823 / ansible_template.yml
Created October 4, 2017 08:17
A playbook to create project directory layout based on the best practices.
- hosts: localhost
vars:
dprefix: ~/playbook/
role_prefix: "{{dprefix}}roles/"
env_files:
- "{{dprefix}}production"
- "{{dprefix}}staging"
var_dirs:
- "{{dprefix}}group_vars/"
@justdoit0823
justdoit0823 / disk_io_size.sh
Created October 9, 2017 00:51
List disk different sizes on linux.
# list disk sector size
fdisk -l | grep "Sector size"
# get disk block size
blockdev --getbsz /dev/sda
@justdoit0823
justdoit0823 / inspect-with-perf.sh
Created October 14, 2017 11:20
Inspect hot paths in program with perf.
# -p refers to process and -t refers to thread
# record stack in process PID
perf record -F 99 -a -p PID -- sleep 30
# hot path like top
perf top -p PID
@justdoit0823
justdoit0823 / network_diagnose.sh
Last active October 24, 2017 13:03
Diagnose network connection.
# list tcp connection whose packet hasn't been acknowledged
ss -tnp|awk '$3 > 0 {print $3, $4, $5, $6, $7}'
# list tcp connection hasn't read received packet
ss -tnp|awk '$2 > 0 {print $3, $4, $5, $6, $7}'
# show timer info about tcp connection
ss -tnpo
@justdoit0823
justdoit0823 / tox.ini
Last active October 26, 2017 07:42
A simple Python automation config file with tox.
[tox]
skipsdist = True
envlist =
3.6-unit
flake8
pydocstyle
pyflakes
@justdoit0823
justdoit0823 / grpc_on_macos.md
Last active October 28, 2017 12:41
test grpc in multiprocess program on macOS.
grpc14 installed: grpcio==1.4.0,protobuf==3.4.0,six==1.11.0
grpc14 runtests: PYTHONHASHSEED='494489219'
grpc14 runtests: commands[0] | uname -a
Darwin yusenbindeMacBook-Pro.local 17.0.0 Darwin Kernel Version 17.0.0: Thu Aug 24 21:48:19 PDT 2017; root:xnu-4570.1.46~2/RELEASE_X86_64 x86_64
grpc14 runtests: commands[1] | python server.py
Greeter client start.
Greeter client received: Hello, you!
(lldb) process attach --pid 13588
Process 13588 stopped
@justdoit0823
justdoit0823 / grpc_on_centos.md
Last active October 28, 2017 12:40
test grpc in multiprocess program on centos.
grpc14 installed: grpcio==1.4.0,protobuf==3.4.0,six==1.11.0
grpc14 runtests: PYTHONHASHSEED='2780338798'
grpc14 runtests: commands[0] | uname -a
Linux iZ25wb48421Z 3.10.0-327.4.5.el7.x86_64 #1 SMP Mon Jan 25 22:07:14 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
grpc14 runtests: commands[1] | python server.py
Greeter client start.
Greeter client received: Hello, you!
#0  0x00007fa98cb6d089 in __libc_waitpid (pid=5384, stat_loc=stat_loc@entry=0x7fff22165e40, options=options@entry=0) at ../sysdeps/unix/sysv/linux/waitpid.c:40
#1  0x00007fa98caf2092 in do_system (line=line@entry=0x7fa986083b78 "bash ./pstack.sh 5381") at ../sysdeps/posix/system.c:148
@justdoit0823
justdoit0823 / ansible_variable_precedence.md
Last active November 3, 2017 10:49
Variable Precedence in ansible.

The last listed variables wins prioritization

  • role defaults [1]

  • inventory file or script group vars [2]

  • inventory group_vars/all

  • playbook group_vars/all

@justdoit0823
justdoit0823 / show_external_ip_address.sh
Last active November 11, 2017 10:17
Show your host's external ip address.
# In China
curl "http://ip.cn/"
# overseas
curl "https://ipinfo.io/"
@justdoit0823
justdoit0823 / go_channel_in_python.py
Last active November 13, 2017 12:56
Simulate golang channel in Python.
import queue
import threading
w_queue = queue.Queue(maxsize=10)
def foo():
w_queue.put('Hello, world')