Skip to content

Instantly share code, notes, and snippets.

View zhiguangwang's full-sized avatar

Zhiguang Wang zhiguangwang

View GitHub Profile
@zhiguangwang
zhiguangwang / install-salt-minion.sh
Last active May 31, 2022 12:56
Install salt-minion on Ubuntu
#!/bin/bash
set -e
SALT_VERSION='3002'
if [ -z "$1" ]; then
echo 'Please run this script with argument <salt-master address>'
exit 1
fi
@zhiguangwang
zhiguangwang / README.md
Created August 26, 2018 08:24
Remove / Uninstall packages marked ‘rc’ on Debian / Ubuntu.

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 December 28, 2017 11:53
Remove password requirement from group sudo when using command "sudo"

Ubuntu

echo "%sudo ALL=(ALL:ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/50-group-sudo-nopasswd
@zhiguangwang
zhiguangwang / optional.cpp
Created September 29, 2017 04:19
sizeof std::optional<T>
#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 March 21, 2019 17:53
Performance cost of passing std::function as parameter.

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 January 17, 2024 14:43
Rename top-level folder while creating a tar.gz file.
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 July 13, 2019 06:32
Install and run Shadowsocks Docker container in Ubuntu Server 16.04

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 July 19, 2016 12:07
Clone, init and pull git repository with multiple submodules.
git lfs clone --recursive [repo].git
git submodule foreach git lfs pull
@zhiguangwang
zhiguangwang / bashrc.bat
Last active July 26, 2016 10:40
batch file to initialize windows command line environment (equivalent with .bashrc)
@echo off
set HOME=%HOMEDRIVE%%HOMEPATH%
@rem Utilites
set PATH=%PATH%;C:\Program Files\WinRAR
set PATH=%PATH%;C:\Program Files (x86)\Microsoft VS Code\bin
set PATH=%PATH%;%HOME%\apps\cmake\3.6.0-win64-x64\bin
set PATH=%PATH%;%HOME%\apps\bin
@zhiguangwang
zhiguangwang / ec2-ping-test.sh
Last active April 11, 2018 07:25
Testing latency between regions.
#!/bin/bash
#
# Usage:
#
# 1. Set SECURITY_GROUP and KEY_NAME to your value
# 2. source ec2-ping-test.sh
# 3. launch_all_instances
# 4. terminate_all_instances
#