Skip to content

Instantly share code, notes, and snippets.

View ngrodzitski's full-sized avatar

Nicolai Grodzitski ngrodzitski

View GitHub Profile
@ngrodzitski
ngrodzitski / network_iface_to_addr.cpp
Last active December 21, 2023 12:13
Network interface to ip addr
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <ifaddrs.h>
//
// network_iface_to_addr()
//
/**
* @brief For a given network interface finds an ipv4 inet address.
@ngrodzitski
ngrodzitski / LUT+SIMD.md
Last active October 10, 2023 20:12
Optimizing LUT for parsing: fast skip to next deciding byte

The problem

For parsers implemented as state machines, a common pattern often emerges: with each subsequent byte, the parser either transitions to a new state or remains in the current state. To determine which of these scenarios applies to a given byte, you can employ a Look-Up Table (LUT) approach.

static constexpr std::array<uint8_t, 256> alphanumeric_lut{
    /* 0x00 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ngrodzitski
ngrodzitski / inotify_with_asio_sample.cpp
Created October 14, 2022 15:36
Old sample using inotify with ASIO
// My old PoC for notify (just for memo).
// Sample based on https://lwn.net/Articles/604686/
// http://think-async.com/Asio/asio-1.11.0/doc/asio/reference/posix__stream_descriptor.html
#include <sys/inotify.h>
#include <iostream>
#include <thread>
#include <stdexcept>
#include <memory>
@ngrodzitski
ngrodzitski / Engeneering_approach_checklist.md
Created May 7, 2021 19:29
A short set of questions to get the idea of what engineering is like at a given place

Source code organization

A physical organization of the code. Is there a established practice (in the scope of all projects or within a single project) regarding the following:

  • project source tree;
  • consistent file naming;
  • rules for putting classes and functions into one file (a file pair (hpp/cpp) to be more precise);
  • rules for naming and formatting (style guide, clang-format);

Code style

Formatting

The most reasonable approach would be relying on clang-format (or a similar tool).

Naming convention

Naming is about how to format a natural language phrase into a single C++ name (using letters’ case, underscores, abbreviations, prefixes, postfixes, etc). Regardless of the "rule" itself it must an established practices shared by all team members.

@ngrodzitski
ngrodzitski / CentOS_5_with_ConanPkgMngr.Dockerfile
Created May 20, 2019 10:06
Sample Dockerfile with setting up Conan on CentOS 5 (old and almost unsupported)
FROM astj/centos5-vault
RUN yum install -y wget mc
RUN wget --no-check-certificate http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo
RUN yum install -y devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++ \
make zlib-devel python-setuptools readline-devel perl sqlite-devel
ENV PATH /opt/rh/devtoolset-2/root/usr/bin/:${PATH}
# wget https://www.openssl.org/source/openssl-1.0.2r.tar.gz
ENV OPENSSLVER 1.0.2r
@ngrodzitski
ngrodzitski / switch_io_context_for_socket_main.cpp
Last active August 28, 2019 03:04
A sample code showing the idea of how to switch socket from one io_context to another.
/**
* A sample code showing the idea of how to switch socket from one io_context to another.
* What is going on here is: accept sockets on context1, and handle echo logic
* on a separate context2.
*
* compiled with:
* g++ -O2 -DNDEBUG -DASIO_STANDALONE -I<PATH_TO_ASIO>/include -std=c++14 -pthread -static-libstdc++ main.cpp
*/
#include <iostream>