Skip to content

Instantly share code, notes, and snippets.

View evanjuang's full-sized avatar

Juang JiaYu evanjuang

  • Taoyuan, Taiwan
View GitHub Profile
@evanjuang
evanjuang / Dockerfile
Created October 19, 2022 08:57
build python image using pyenv
ARG CENTOS_IMG=stream8
FROM quay.io/centos/centos:$CENTOS_IMG
ARG PYTHON_VERSION=3.8.13
ENV PYENV_GIT_TAG=v2.3.5
ENV PYENV_ROOT=/root/.pyenv
ENV PATH=$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
ENV PYTHON_CONFIGURE_OPTS="--enable-shared"
import logging
import os
import subprocess
import signal
import time
import tempfile
import sh
import shlex
from pathlib import Path
from datetime import datetime
@evanjuang
evanjuang / requests_utils.py
Last active June 22, 2022 08:32
python - requests utils
import io
import tarfile
from pathlib import Path
import magic
import requests
def is_file_exist(url: str) -> bool:
try:
@evanjuang
evanjuang / dmidecode_type.py
Created June 30, 2021 01:52
Python - Parse output from "dmidecode -t"
import subprocess
import json
from enum import Enum
class DmiType(Enum):
Bios = 0
System = 1
BaseBoard = 2
@evanjuang
evanjuang / read_pci_config.py
Created June 30, 2021 01:49
Python - Read PCI configuration space
import struct
PATH = '/sys/bus/pci/devices/0000:03:00.1/config'
with open(PATH, 'rb') as fd:
data = fd.read()
r, = struct.unpack('<H', data[0:0+2])
if r == 0x8086:
@evanjuang
evanjuang / exceptions.py
Last active June 18, 2021 03:51
Python requests sample code
class HTTPRequestError(Exception):
pass
class HTTPClientError(Exception):
pass
class HTTPServerError(Exception):
pass
@evanjuang
evanjuang / clean_py.sh
Created November 20, 2020 07:09
[clean python build find] #python #shell
find . -regex '^.*\(__pycache__\|\.py[co]\)$' -delete
@evanjuang
evanjuang / find_mount_info.sh
Created November 16, 2020 03:42
[mount info] #shell #snippet
cat /proc/self/mountinfo | grep /home/repo | awk '{print $4 " ==> " $5}'
# output to markdown format
echo -e "|source|dest|\n|----|----|" > out.md
cat /proc/self/mountinfo | grep /home/repo | awk '{printf "|%s|%s|\n", $4, $5}' >> out.md
@evanjuang
evanjuang / wsl-setup.md
Last active April 17, 2019 08:12
[devtool - wsl ubuntu] #windows #linux #devtool
@evanjuang
evanjuang / init.vim
Last active April 17, 2019 08:10
[devtool - neovim] #linux #devtool
" ==================== VIM PLUG ==================
call plug#begin()
" autocompletion (also a linter - diagnostics)
" Plug 'Valloric/YouCompleteMe', { 'do': './install.py --clang-completer' }
" airline (powerline)
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'