Ben Chuanlong Du's Blog

And let it direct your passion with reason.

Seed Many RNGs in Rust

There are different ways to seed many RNGs (for parallel RNGs). Below summarizes 3 popular ways. Seeding RNGs using std::collections::hash_map::RandomState or rand::thread_rng is preferred.

Seed Using System Time

use std::time::{SystemTime, UNIX_EPOCH};
use rand::SmallRng;

fn main () {
    let seed = SystemTime::now()
        .as_nanos …

Tips on Bytehound

Bytehound works with Rust stable (Rust nightly is not required) .


apt-get install gcc nodejs npm
npm install -g yarn
cargo build --release -p bytehound-preload
cargo build --release -p bytehound-cli

Or if you use icon,

icon bytehound -ic


Run your application with bytehound to collect memory usage data.

export …

GitHub API

Shell Command - gh

gh is GitHub's official command-line tool. Persoanlly, I'm not a fan of gh mainly because I'm not a fan of writing complicated (>10 lines) shell scripts.

Python Bindings - ghapi

  1. ghapi provides 100% always-updated coverage of the entire GitHub REST API by automatically converting the OpenAPI spec to a Pythonic API. ghapi is always up to date with the latest changes to GitHub APIs.

Hands on the Python Library pexpect

Tips and Traps

  1. The command-line tool of some (e.g., network) applications might be slow to authenticate. If you use pexect to automate such a command-line tool, it is best to wait for sometime after sending password using child.sendline(passwd). If the authentication has ouput on both success and failure, a smart way is to wait for the success or failure message to come out.

IPython Is the Best Shell

IPython is the Best Shell!

  1. Use IPython as much as possible.

    • IPython has virtues of both shell and Python.
    • You should avoid using shell scripts for complicate tasks any way.
  2. If you do want to use a Unix/Linux shell, I'd suggest you stick to Bash unless Linux distributions start …