Skip to content

Instantly share code, notes, and snippets.

@ivcn
ivcn / .vimrc
Created April 18, 2023 09:45
My vimrc
set nocompatible "be Improved
filetype off
"syntax on " enable syntax processing
set background=light
colorscheme gruvbox
""""""" tab settings
set tabstop=4 " number of visual spaces per TAB
set softtabstop=4 " number of spaces in tab when editing
set expandtab " tabs are spaces
@ivcn
ivcn / install_boost.sh
Created January 21, 2021 20:46
How to install Boost to custom folder
DIR=/path/to/folder/
./bootstrap.sh --prefix=${DIR} --includedir=headers --libdir=dist --with-libraries=date_time
./b2 --prefix=${DIR} install
@ivcn
ivcn / distributions.cpp
Created May 23, 2020 11:56
Simulation of simple discrete distributions
#include <chrono>
#include <iostream>
#include <random>
#include <vector>
using std::cout;
using std::endl;
using std::vector;
class TestRandom {
@ivcn
ivcn / sample.md
Last active April 9, 2020 21:07
How to use TShark

To print some network packets:

tshark [options] -r input.pcap.gz "Wireshark display filter" [-w output.pcap]

Useful options:

  • -r - file to read
  • -w - file to write
  • -2 - two-pass analysis
  • -P - print packet summary
  • -V - print packet details (fields of dissected protocols)
@ivcn
ivcn / thread_pool.cpp
Created May 16, 2017 18:50
An example of thread pool using two conditional variables
#include <iostream>
#include <deque>
#include <functional>
#include <thread>
#include <condition_variable>
#include <mutex>
#include <random>
//thread pool
class ThreadPool
@ivcn
ivcn / resource.h
Created May 9, 2017 22:07
An examle of service providing pre-initialization, storing and concurrent access to some resources.
#ifndef _RESOURCE_H_
#define _RESOURCE_H_
#include <thread>
class Resource {
public:
static Resource *make(int partNumber) {
int timeToSleep = partNumber;
//sleep(timeToSleep);
@ivcn
ivcn / producer_consumer.cpp
Created April 9, 2017 16:04
Simple implementation of producer-consumre pattern in C++
template<typename ElementType>
class Queue {
public:
Queue(size_t size) :
buffer(size),
front(0),
end(0) {}
void push(ElementType newElement) {
std::unique_lock<std::mutex> lk(m);
@ivcn
ivcn / test.glsl
Created April 8, 2017 11:10
simple 2D shader
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 center = iResolution.xy / 2.0;
float r1 = iResolution.y / 5.0;
float r2 = iResolution.y / 3.0;
vec2 uv = fragCoord.xy / iResolution.xy;
float dist = distance(fragCoord.xy, center);
if( dist >= r1 && dist <= r2) {
float d = (dist-r1)/(r2-r1);
@ivcn
ivcn / deadlock.cpp
Created April 7, 2017 11:31
Simple deadlock example in C++
int main() {
std::mutex m1;
std::mutex m2;
std::thread t1([&m1, &m2] {
print("1. Acquiring m1.");
m1.lock();
std::this_thread::sleep_for(std::chrono::milliseconds(10));
print("1. Acquiring m2");
m2.lock();
});
@ivcn
ivcn / thread_handle.cpp
Created April 6, 2017 14:05
Wrapper for std::thread. Provides automatic join of owned thread.
class thread_handle {
private:
std::thread t;
int id;
public:
template<typename F, typename... Args>
thread_handle(int _id, F&& f, Args&&... args) :
id(_id),
t(std::move(std::thread(f, args...))) {