SSH config for multiple hops in Linux

Often some hosts in corporate network are available only from several gateway machines. The scheme looks like that: you connect to gateway ssh -A and then to desired host from gateway machines ssh -A But the problem arises when you want to copy or download something from You have to do it in two hops, because is not available from your machine directly. The solution is ssh forwarding. Just add the following (edit according your network settings) lines to ~/.ssh/config:

Example of CMake file for CUDA+CPP code

Makefiles are quite straightforward and easy to write (in reasonable situations). But GNU Make is not crossplafrom. CMake is cross-platform, cross-application (it can generate projects for different IDEs and Makefile itself).

It also allows you to split source directory and directory with intermediate files and compiled binary. Now CMake natively supports CUDA.

throw() in function signature in C++

There is base class exception in standard library (header <exception>). It has default constructor, copy constructor, copy operator and destructor and virtual what() function. Latter returns string with additional information about exception.

Sort strings from file in C++

The very simple and common test program is to read bunch of strings from input file (let it be input.txt), sort them and write down to another file (output.txt). There is an implementation with small bug: it adds extra empty line. I’ve modified original code a bit, so now it works correctly (note: if have last empty line in the input, you will have an empty line in the output). Fixed code is provided below.

Randomized quicksort implementation in C++

Quicksort has $O(N\log(N))$ computational complexity in best and average cases, $O(N^{2})$ for bad case. Extremely bad cases may be avoided by using randomized Quicksort.

Heapsort implementation in C++

Heapsort is one of the fastest sorting algorithms. The best and the worst cases for heapsort have same $O(n\log(n))$ performance.

At first heapsort creates heap from data with buildHeap function. Heap is organized in linear array as follows. Every $i$-th element has two children: $(2i)$-th element and $(2i+1)$-th one. The biggest element of the array is placed on the top of the heap.