Skip to main content

· One min read
Hreniuc Cristian-Alexandru

Installl nvm

# Check latest release: https://github.com/nvm-sh/nvm/releases/latest
# This commands also adds the paths to your ~/.bashrc
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
source ~/.bashrc

Install latested node version and use it

nvm install --lts
nvm use --lts
# Or
nvm use 16.15.0

Install yarn and upgrade npm:

npm install --global yarn

npm install -g [email protected]

Install RESTer extension.

· 2 min read
Hreniuc Cristian-Alexandru

Install the c++ compiler and the other things:

sudo apt-get install build-essential curl

Note: You should also check this post: Preparing C++ Dev infrastructure

Tmux and tmuxinator:

sudo apt-get install tmux tmuxinator

Others:

sudo apt-get install liblz4-tool

# To uncompress a lz4
lz4 -dc --no-sparse archive.tar.lz4 | tar xf -

sudo apt-get install vim
sudo apt-get install sqlitebrowser

MariaDB

sudo apt update
sudo apt install mariadb-server
sudo mysql_secure_installation
sudo mariadb

GRANT ALL PRIVILEGES on *.* to 'root'@'localhost' IDENTIFIED BY 'root';
FLUSH ALL PRIVILEGES;

Docker:

Source

sudo apt-get update

sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null


sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

sudo usermod -aG docker $USER

Kubernetes utils:

Source

sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl

sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg

echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

sudo apt-get update
sudo apt-get install -y kubectl

From snap:

  • spotify
  • vscode(you can download it from ms website directly)
  • dbeaver

· One min read
Hreniuc Cristian-Alexandru

I usually have a data folder in my home folder, where I keep all my data, including the cache of my browser.

When I switch PCs I have to copy that folder on my new pc, if I try to archive the folder it will create a corupted compressed archive or the compression will fail.

So, to fix this I had to follow the following steps:


# Create a copy of the folder with rsync
# Will copy all folders/files from `data` inside the `data_backup` folder
sudo rsync -a --info=progress2 /home/chreniuc/data/ /home/chreniuc/data_backup/

# Create an archive
tar -cf - data_backup | lz4 -c > data_backup_29.04.2022.tar.lz4

# Copy the archive where you want

cp data_backup_29.04.2022.tar.lz4 destination

# To uncompress a lz4
lz4 -dc --no-sparse data_backup_29.04.2022.tar.lz4 | tar xf -

· One min read
Hreniuc Cristian-Alexandru

I've found this. I haven't tried it, but I want to save it just in case.

Contents:

Boost has experimental CMake support. You have to do a bit of dev to get it working but we've had good experiences so far.

set(BOOST_INCLUDE_LIBRARIES system thread) # enabled libraries
set(BOOST_ENABLE_CMAKE ON) # CMake support
FetchContent_Declare(boost GIT_REPOSITORY https://github.com/boostorg/boost.git ...

The above will get you the compiled libs working. For the header library (Boost::boost aka Boost::headers) there doesn't seem to be CMake support as yet so we wrote a few lines of CMake code to iterate through the FetchContent source directory and added all include folders to a new IMPORTED INTERFACE target.

· 2 min read
Hreniuc Cristian-Alexandru

Tools

# Make sure pip is using python3
pip install conan

# Cmake
sudo apt-get install cmake

# gcc + make
sudo apt-get install build-essential

Install clang for automatic formatting:

#!/bin/bash

# Use this script to install the clang formatter and all its utilities.
# Install Clang(Used for clang-format)
# ============================================================================ #
mkdir -p ~/programs/clang && cd ~/programs/clang &&
# http://releases.llvm.org/download.html
clang_version="9.0.0" &&
archive_name="clang+llvm-${clang_version}-x86_64-linux-gnu-ubuntu-18.04" &&
wget http://releases.llvm.org/${clang_version}/${archive_name}.tar.xz &&
tar xf ${archive_name}.tar.xz &&
rm -Rf ${archive_name}.tar.xz &&
unlink clang_latest # Just in case there was another sym link
ln -sf ${archive_name} clang_latest &&
(
echo "CLANG_INSTALL_PATH=\"/mnt/programs/clang/clang_latest\"" &&
echo "export PATH=\"\${CLANG_INSTALL_PATH}/bin:\$PATH\"" &&
echo -n "export LD_LIBRARY_PATH=\"\${CLANG_INSTALL_PATH}/lib" &&
echo ":\$LD_LIBRARY_PATH\""
) >> ~/.bashrc
# ============================================================================ #

IDE

Use QtCreator.

Activate these plugins:

Go to Help -> About plugins:
- C++
- Check ClangCodeModel
- Check ClangFormat
- Beautifier
- Code Analyzer
- Check ClangTools
- Utilities
- Check Todo

Set these settings:

Go to Tools -> Options:
- Text Editor
- Behavior:
- Tab policy: Spaces Only
- Tab size: 2
- Indend size: 2
- Align continuation lines: With Spaces
- Clean whitespace (upon saving)
- Display:
- Display right margin at column: 80
- Display line numbers
- Display folding markers
- Visualize whitespace
- Highlight search results on the scrollbar
- Highlight current line
- Highlight blocks
- Animate matching parentheses
- Highlight matching parentheses
- Completion:
- Enable Doxygen blocks
- Generate brief description
- Add leading asterisks
- Beautifier
- Enable auto format on file save
- Clang Format
- Use predefined style: `File`
- Debugger
- General:
- Set breakpoints using full absolute path

· 6 min read
Hreniuc Cristian-Alexandru

We wanted to optimize the way we combine multiple protobuf messages. Our scenario was this, we had a NestedRepeatedMessage that contained a NestedSingleInt message. We were creating a NestedRepeatedMessage which was the same for multiple users, so were serializing it once and we were posting it to be sent to that user. After some tests, we detected that sending 1 message per send operation is verry expensive, so we had to find a solution to combine multiple serialized messags before sending them.

The first solution was to, keep a reference to the protobuf object that was used to serialize, and if the client had multiple messages in the queue, we would create a big NestedRepeatedMessage and we would create a copy of each NestedSingleInt from those NestedRepeatedMessage from the queue. If there was only one element in thew queue, we would use the serialized version. This was also expensive..

Our next step, was to find a way to use the already serialized string. After understanding how the the protobuf encoding works, we've noticed that if append the serialized NestedRepeatedMessage messages, it results the same serialized string as the one from above, where we were doing a copy of all messages, adding them to a big message and then re-serializing it.

Below you can find all steps that were done to get to this conclusion.

· One min read
Hreniuc Cristian-Alexandru

If you return a value from a method and you assing it to the a const reference, that value will be kept alive as long as the const reference is alive:

string get() { return "string"s; }

int main()
{
const string& ref_to_temp = get();
cout << ref_to_temp << endl;
}

Better explaination: https://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/ or stackoverflow: https://stackoverflow.com/questions/2784262/does-a-const-reference-class-member-prolong-the-life-of-a-temporary

Or standard explaination: 8.5.3/5, here