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 / 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 / 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 / Config-shadowsocks-libev-on-Linux.md
Last active May 4, 2022 15:22
Config shadowsocks-libev on Linux

With no time updating Twist, I wrote this extremly simple script to setup shadowsocks-libev both server and client.

apt-get update -y
apt-get upgrade -y
apt-get dist-upgrade -y
apt-get autoremove -y
apt-get install --no-install-recommends -y gettext build-essential autoconf libtool libpcre3-dev asciidoc xmlto libev-dev libc-ares-dev automake golang golang-go fail2ban apache2 unzip git
git clone https://github.com/jedisct1/libsodium --branch master
pushd libsodium
bash autogen.sh
@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 / 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 / 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 / Build-OpenCV-with-CUDA-and-TBB-Visual-Studio.md
Last active March 14, 2023 13:29
Build OpenCV with CUDA and TBB Visual Studio

OpenCV is a library of programming functions mainly aimed at real-time computer vision and it officially compiled without support for NVIDIA CUDA, INTEL TTB and OpenCL library, that's why we need to rebuild OpenCV with a custom configuration manually.

CUDA is a parallel computing platform and programming model developed by Nvidia for general computing on its own GPUs (graphics processing units). CUDA enables developers to speed up compute-intensive applications by harnessing the power of GPUs for the parallelizable part of the computation.

Intel TBB (Threading Building Blocks) makes parallel performance and scalability accessible to software developers who are writing loop- and task-based applications. Build robust applications that abstract platform details and threading mechanisms while achieving performance that scales with increasing core count.

To begin with, these software libraries should be pre-installed and configured correctly:

@Unbinilium
Unbinilium / Get-started-with-OpenCV-CUDA-cpp.md
Last active October 30, 2023 05:59
Get started with OpenCV CUDA C++

First your OpenCV should be compiled with CUDA (and OpenGL) support to test all this features. Detect your CUDA hardware with OpenCV CUDA by:

#include <iostream>
using namespace std;

#include <opencv2/core.hpp>
using namespace cv;

#include <opencv2/cudaarithm.hpp>
using namespace cv::cuda;