Skip to content

Instantly share code, notes, and snippets.

@liviaerxin
liviaerxin / setup.md
Last active March 8, 2023 06:50
OpenVPN Configuration #tools

OpenVPN Configuration

Client

Configure client your_client.ovpn file,

# redirect all default traffic via the VPN
redirect-gateway def1
@liviaerxin
liviaerxin / gracefully_kill.md
Last active March 8, 2023 06:49
Gracefully Kill #python

Gracefully Kill Process

Unix/Linux

On Unix or Linux, it's easy to gracefully kill a application by sending it the SIGTERM signal. If its process ID is 1234, you can simply run kill 1234 or kill -s TERM 1234 or kill -15 1234.

Inside target-killed application, you receive the SIGTERM signal, clean up(such as data backup,...etc) and exit.

A simple python solution,

@liviaerxin
liviaerxin / python_logging_configuration_examples.md
Last active March 8, 2023 06:50
Python Logging Configuration Examples Best Practice #python
@liviaerxin
liviaerxin / c_project_makefile_template.md
Created May 9, 2021 13:26
Makefile Template for Small/Middle-Sized C Project
@liviaerxin
liviaerxin / an_executable_linking_shared_lib_by_using_@rpath_@executable_path.md
Created May 10, 2021 15:52
An executable link a shared library by setting @rpath, @executable_path during `clang` linking stage without using `install_name_tool` to hack

Original documents in clang, change dependent shared library install name at link time I've been hitting my head against this for some time and think I have finally figured out how to do this without using install_name_tool, at least for Mac OS 10.9 and later (as far as I've tested).

While you may have already figured this out, I'm posting it here in case anyone else needs it.

Basically you have two options:

  1. You can do it when you compile the library, defining its install_name in terms of @executable_path
@liviaerxin
liviaerxin / python_open_file_mode.md
Last active March 8, 2023 06:50
Python `open()` file mode for read/write, create?, and truncat? #python

Open() File Mode In Python

Here's a table of modes:

r r+ w w+ a a+
read + + + +
write + + + + +
write after seek + + +
@liviaerxin
liviaerxin / check_is_translated.md
Last active June 16, 2023 11:46
Determine Universal App Is Running as a Native or Translated Binary #apple-silicon

Check Universal App Is Running as Native or Translated Binrary

On Apple silicon, arm app is running as native binary and x86_64 app is translated by Rosseta before executing.

Make Test Demo

❯ clang -o arm_proc_translated proc_translated.c -target arm64-apple-macos11
❯ clang -o x86_64_proc_translated proc_translated.c -target x86_64-apple-macos11
❯ lipo -create -output universal_proc_translated x86_64_proc_translated arm_proc_translated
@liviaerxin
liviaerxin / .zshrc
Last active June 8, 2023 15:08
Development Tools Setup in Apple Silicon #apple-silicon
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
@liviaerxin
liviaerxin / custom_p10k_os_icon_mac_m1.md
Last active June 12, 2021 14:03
Custom powerlevel10k OS_Icon to Prompt Whether in `arm64` or `x86_64` Termial in Apple Silicon #Apple Silicon

Customize powerlevel10k OS_Icon to Prompt Whether in arm64 or x86_64 Termial in Apple Silicon #Apple Silicon.

Configure ~/.p10k.zsh:

  # Custom icon.
  if [[ "$(uname)" == "Darwin" ]]; then 
 typeset -g POWERLEVEL9K_OS_ICON_CONTENT_EXPANSION="$(uname -m) $(print_icon 'APPLE_ICON')" #'⭐'