Skip to content

Instantly share code, notes, and snippets.

View Unbinilium's full-sized avatar
🌃
lost in the nowhere

Unbinilium Unbinilium

🌃
lost in the nowhere
View GitHub Profile
@Unbinilium
Unbinilium / Accelerate-CMake-build-speed-by-using-multi-cores.md
Last active October 30, 2019 04:55
Accelerate CMake build speed by using multi-cores

Normally we build from source code by sudo make, but it seems always slow in a more awkward way. Let's see the flags by sudo make -h:

Usage: make [options] [target] ...
Options:
  -b, -m                      Ignored for compatibility.
  -B, --always-make           Unconditionally make all targets.
  -C DIRECTORY, --directory=DIRECTORY
                              Change to DIRECTORY before doing anything.
  -d                          Print lots of debugging information.
  --debug[=FLAGS]             Print various types of debugging information.
@Unbinilium
Unbinilium / Update-Ubuntu-kernel.md
Last active October 30, 2019 05:23
Update Ubuntu kernel

For Ubuntu users who wandering to support newer versions of hardware or getting new features, it's recommaned to update Ubuntu kernel. We could do it by sudo gedit updatekernel.sh && chmod -x updatekernel.sh && bash updatekernel.sh to create a bash script named updatekernel.sh in current folder and paste the code below before saved. Then it automatically set executable permission and run to update your Ubuntu kernel to the newest version.

KERNELVER="$(wget -qO- http://kernel.ubuntu.com/~kernel-ppa/mainline/ | awk -F'\"v' '/v[4-9]./{print $2}' | cut -d/ -f1 | grep -v -  | sort -V | tail -1)"
SYSTYPE="$(dpkg --print-architecture)"
[ "$SYSTYPE" = "amd64" ] && KERNEL="$(wget -qO- http://kernel.ubuntu.com/~kernel-ppa/mainline/v${KERNELVER}/ | grep "linux-image" | grep "generic" | awk -F'\">' '/amd64.deb/{print $2}' | cut -d'<' -f1 | head -1)"
[ "$SYSTYPE" = "i386" ] && KERNEL="$(wget -qO- http://kernel.ubuntu.com/~kernel-ppa/mainline/v${KERNELVER}/ | grep "linux-image" | grep "generic" | awk -F'\">' '/
@Unbinilium
Unbinilium / Simple-network-optimization-Linux.md
Last active October 30, 2019 05:54
Simple network optimization on Linux

It is required to edit /etc/sysctl.conf by sudo nano /etc/sysctl.conf and add the configuration below to the end of the file.

net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.ipv4.tcp_fastopen = 3

This means to config Google BBR and TCP fastopen support on your operation system. Want another choice or check if the Google BBR supported by default, type sysctl net.ipv4.tcp_available_congestion_control to show all supported congestion control modules.

Use sudo sysctl -p to apply the changes to your operation system. Check if BBR module is installed in kernelvuse lsmod | grep bbr and find if string bbr is in outputs.

@Unbinilium
Unbinilium / Use-undefined-array-in-cpp.md
Last active October 30, 2019 11:32
Use undefined array in cpp

In C/C++, we can define multidimensional arrays in simple words as array of arrays. Data in multidimensional arrays are stored in tabular form (in row major order). A dynamic 2D array is basically an array of pointers to arrays. So you first need to initialize the array of pointers to pointers and then initialize each 1d array in a loop. Example below using new:

#include <iostream>

int main()
{
    int row = 3, col =3;
    array = (int**) new int* [row];
    for (int i = 0; i < row; i++) array[i] = new int[col];
    for (int i = 0; i < row; i++)
@Unbinilium
Unbinilium / Expend-max-number-of-open-files-on-Linux.md
Last active October 30, 2019 11:33
Expend max number of open files on Linux

UNIX/Linux operating systems have the ability to limit the amount of various system resources available to a user process. These limitations include how many files a process can have open, how large of a file the user can create, and how much memory can be used by the different components of the process such as the stack, data and text segments.

To unlimit the max number of opened files, use sudo nano /etc/security/limits.conf to edit /etc/security/limits.conf and add something like this below.

*                soft    nofile           512000
*                hard    nofile          1024000

The soft is for enforcing the soft limits and the hard is for enforcing hard limits. For this both number type is unsigned integer.

@Unbinilium
Unbinilium / Config-Qt-Creator-with-OpenCV.md
Last active November 3, 2019 02:41
Config Qt Creator with OpenCV

Firstly we installed opencv by compiling it form its source and libraries installed in /usr/local/lib. We could show the files in this directory by la /usr/local/lib | grep libopencv then it shows:

libopencv_calib3d.so
libopencv_calib3d.so.4.1
libopencv_calib3d.so.4.1.2
libopencv_core.so
libopencv_core.so.4.1
libopencv_core.so.4.1.2
libopencv_dnn.so
libopencv_dnn.so.4.1
@Unbinilium
Unbinilium / Command-lines-proxy.md
Last active November 3, 2019 06:51
Command lines proxy

Usually we got a system based proxy but it not works in command line tools like the terminal. We could easily add such proxy by replacing the proxy information below and run them in terminal.

export http_proxy=protocol://username:password@proxyhost:port/
export ftp_proxy=protocol://username:password@proxyhost:port/
export telnet_proxy=protocol://username:password@proxyhost:port/

The protocol should be http, https or socks5 depends on what type of proxy you are using. Further more, we could add this to ~/.*shrc to initialize proxy when terminal start by sudo nano ~/.*shrc.

Let apt work with socks5 proxy, add -o Acquire::http::proxy="protocolh://proxyhost:proxyport/" as arguments, for example:

@Unbinilium
Unbinilium / opencv-tutorial-transparent-mask-overlay-to-recognized-faces.md
Last active January 24, 2020 15:46
OpenCV Tutorial transparent mask overlay to recognized faces

As the death toll from the Wuhan coronavirus still risen, I felt anxious and helpless through everyone here were talking and laughing on New Year's Eve. Not sure what should I do and I just wrote this python3 program to make people aware of the importance of wearing respirator masks when defeating the virus.

In this program, we use CascadeClassifier to add respirators masks to the recognized faces in the capture. Before everything start, we have to import the necessary packages:

import argparse
import cv2

We use argparse to construct the argument parse for more flexible usage. The respirator image cloud be found on eBay, Google... and transparent background required as .png format. The haarcascade_frontalface_default.xml could be found at OpenCV official git repository https://github.com/opencv/opencv/tree/master/data/haarcascade.

@Unbinilium
Unbinilium / build-pytorch-and-pytorch-vision.md
Created February 3, 2020 05:43
Build PyTorch and PyTorch Vision
  • Install dependencies
sudo apt-get install -y libopenblas-dev libblas-dev m4 cmake cython python3-dev python3-yaml python3-setuptools libavutil-dev libavcodec-dev libavformat-dev libswscale-dev
  • Build PyTorch from the source
git clone --recursive https://github.com/pytorch/pytorch
pushd pytorch
git submodule update --remote third_party/protobuf
@Unbinilium
Unbinilium / migration.md
Last active May 8, 2021 11:37
Migration

I migrated my gist to my website:

  • WebSite https://unbinilium.github.io/