Get actual elapse time in CPP

#include <chrono>

int main() {
	std::chrono::time_point <std::chrono::system_clock, std::chrono::duration<double, std::milli>> then = std::chrono::high_resolution_clock::now();;

	// ... do something ...

	std::chrono::time_point <std::chrono::system_clock, std::chrono::duration<double, std::milli>> now = std::chrono::high_resolution_clock::now();;
	double elapseTimeInMS = (now - then).count();

	return 0;
}

Shorter:

#include <chrono>

using namespace std;

int main() {
	auto then = chrono::high_resolution_clock::now();

	// ... do something ...

	auto now = chrono::high_resolution_clock::now();
	double elapseTimeInMS = chrono::duration<double, milli>(now - then).count();

	return 0;
}
cpp 

Firefox tabs in multiple rows

  1. Go to about:config, enable config toolkit.legacyUserProfileCustomizations.stylesheets.
  2. Go to about:support > Profile Directory > Open Directory. Firefox profile directory will be openned in new window.
  3. In your profile directory, create folder chrome if not exist.
  4. Go to folder chrome, create file userChrome.css.
  5. Copy content from multi-row_tabs.css into userChrome.css.
  6. Restart Firefox.
firefox  css 

Active Application Launcher on Latte Dock by Super button

  • Right click on the dock > Layouts > Configure…
  • In Settings window, go to Preferences tab
  • In Actions section > Tick Press ⌘ to activate Application Launcher

Or

  • Open ~/.config/kwinrc, then add:

    ...
    [ModifierOnlyShortcuts]
    Meta=org.kde.lattedock,/Latte,org.kde.LatteDock,activateLauncherMenu
    ...
    
  • Reload KWin:

    $ qdbus org.kde.KWin /KWin reconfigure
    

    Github QA

Generate GPG key non-interactively

Put information for gen key in a text file, eg. gpg_gen_key:

Key-Type: 1
Key-Length: 2048
Subkey-Type: 1
Subkey-Length: 2048
Name-Real: My Name
Name-Email: my.email@example.com
Expire-Date: 0
Passphrase: secretpass

Gen key with above text file:

gpg --batch --gen-key gpg_gen_key
gpg 

NGINX Basic Authentication

Required package

  • For Debian: apache2-utils.

    sudo apt-get install apache2-utils
    
  • For Fedora: httpd-tools.

    sudo dnf install httpd-tools
    

Create password file

Run with -c option if /etc/nginx/.htpasswd does not exist:

sudo htpasswd -c /etc/nginx/.htpasswd user1

If .htpasswd already exists, don’t use -c option or file will be overwritten.
To add more user to password file.

sudo htpasswd /etc/nginx/.htpasswd user2
[Read More]
nginx 

Get started with Mosh

What is Mosh

Mosh is a replacement for interactive SSH terminals.

Mosh doesn’t listen on network ports or authenticate users. The mosh client logs in to the server via SSH, and users present the same credentials (e.g., password, public key) as before. Then Mosh runs the mosh-server remotely and connects to it over UDP.

[Read More]
mosh  ssh