Tips and Traps¶
Starting from Python 3.7,
dict
preserves insertion order (i.e.,dict
is ordered). There is no need to useOrderedDict
any more in Python 3.7+. However,set
in Python is implemented as an unordered hashset and thus is neither ordered nor sorted. A trick to dedup an iterablevalues
Expose Local Services to Public Using ngrok
You can expose a local service to public using ngrok
.
Follow instructions in the
official documentation of ngrok
to setup ngrok
.
-
Install ngrok.
sudo snap install ngrok
-
Login to ngrok.com to identify your ngrok token.
-
Connect your account following instructions.
ngrok config add-authtoken your_token
-
Start a http tunnel forwarding …
Working with Spreadsheet in Python
It is suggested that you avoid using Excel files (or other spreadsheet tools) for storing data. Parquet file is currently the best format for storing table-like data. If you do want to interact and manipulate your data using Excel (or other spreadsheet tools), dump your data into CSV files and …
The Right Way to Export PATH in Shell
Some people suggest exporting PATH
only in .bash_profile
instead of in .bashrc
(for Bash).
The helps but does not resolve the issue of possible duplicated paths in $PATH
.
The right way is to check for existence of the path in the $PATH
environment variable first,
and add it only when …
Parallel RNGs With Rayon in Rust
The Rust Rand Book - Parallel RNGs has a very good summary about parallel RNGs. It also gives code examples using the rayon library. However, a few things to notice.
-
rand::ThreadRng (obtained by calling rand::thread_rng) is often used in code examples of parallel RNGs as it uses thread-local storage …
Useful Rust Crates for Developing Command Line Apps
Command-line Arguments Parsing
clap
clap is a simple to use, efficient, and full-featured Command Line Argument Parser.
structopt
Parse command line argument by defining a struct.
Terminal Interface
ratatui
RataTUI is a library to build rich terminal user interfaces or dashboards
tui
tui is a library to build rich terminal …