Skip to content

Instantly share code, notes, and snippets.

Zhiguang Wang zhiguangwang

Block or report user

Report or block zhiguangwang

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@zhiguangwang
zhiguangwang / README.md
Last active May 5, 2019
bash curl loop
View README.md
curl-loop() { while true; do echo "$(date +%Y-%m-%dT%H:%M:%S%z) $(curl --silent --show-error ${1})"; sleep ${2:-0.5}; done }

Usage

curl-loop <url> [interval]
@zhiguangwang
zhiguangwang / README.md
Last active Nov 19, 2018
SSH Tunnelling
View README.md
ssh-tunnel() { nohup ssh -o ServerAliveInterval=15 -f -N -L ${1}:${2} ${3} > /dev/null 2>&1; }

Usage

ssh-tunnel <local-port> <remote-host>:<remote-port> <bastion>
@zhiguangwang
zhiguangwang / 16.04.sh
Last active Sep 18, 2018
Install salt-minion (2018.3) on Ubuntu
View 16.04.sh
#!/bin/bash
set -e
if [ -z "$1" ]; then
echo 'Please run this script with argument <salt-master address>'
exit 1
fi
SALT_MASTER=$1
@zhiguangwang
zhiguangwang / README.md
Created Aug 26, 2018
Remove / Uninstall packages marked ‘rc’ on Debian / Ubuntu.
View README.md

Remove / Uninstall packages marked ‘rc’ on Debian / Ubuntu.

While checking the status of packages using dpkg, it is possible to see a ‘rc’ state for some unused packages, this corresponds to:

  • r: the package was marked for removal
  • c: the configuration files are currently present in the system

In other words: the package is not completely removed (config files are still present), but not installed anymore (and obviously not used).

To see a list of packages marked as ‘rc’:

@zhiguangwang
zhiguangwang / README.md
Created Dec 28, 2017
Remove password requirement from group sudo when using command "sudo"
View README.md

Ubuntu

echo "%sudo ALL=(ALL:ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/50-group-sudo-nopasswd
@zhiguangwang
zhiguangwang / optional.cpp
Created Sep 29, 2017
sizeof std::optional<T>
View optional.cpp
#include <iostream>
#include <string>
#include <optional>
int main()
{
std::cout << "sizeof bool is " << sizeof(bool) << '\n';
std::cout << "sizeof std::optional<bool> is " << sizeof(std::optional<bool>) << "\n\n";
std::cout << "sizeof short is " << sizeof(short) << '\n';
@zhiguangwang
zhiguangwang / README.md
Last active Mar 21, 2019
Performance cost of passing std::function as parameter.
View README.md

Environment

  • Intel i7-4790 @ 3.60GHz
  • Ubuntu 14.04.5 LTS (Windows Subsystem Linux)
  • GCC 6.2.0
  • Clang 3.9.1
  • CXXFLAGS -std=c++14 -O2

Output

@zhiguangwang
zhiguangwang / README.md
Last active May 14, 2019
Rename top-level folder while creating a tar.gz file.
View README.md
tar czfv NEW_NAME.tar.gz OLD_NAME --transform s/OLD_NAME/NEW_NAME/

Note: this only works with GNU Tar.

Example

we want to tar /opt/zlib/1.2.11 into zlib-1.2.11.tar.gz, and we want the top-level folder inside that tar.gz file to be zlib-1.2.11, not 1.2.11:

@zhiguangwang
zhiguangwang / shadowsocks-docker-ubuntu.md
Last active Mar 22, 2018
Install and run Shadowsocks Docker container in Ubuntu Server 16.04
View shadowsocks-docker-ubuntu.md

Install and run Shadowsocks Docker container in Ubuntu Server 16.04

# Configurations for shadowsocks
export SSPORT=[your shadowsocks port]
export SSPASSWORD=[your shadowsocks password]

# Install docker prerequisites
sudo apt update
sudo apt install apt-transport-https ca-certificates
@zhiguangwang
zhiguangwang / git-repo-init.sh
Created Jul 19, 2016
Clone, init and pull git repository with multiple submodules.
View git-repo-init.sh
git lfs clone --recursive [repo].git
git submodule foreach git lfs pull
You can’t perform that action at this time.