Skip to content

Instantly share code, notes, and snippets.

@IMelker
IMelker / bitrate_estimator.hpp
Created July 21, 2023 07:42
Bayesian bitrate estimator
#include <cmath>
#define INITIAL_WINDOW_MS 500
#define NONINITIAL_WINDOWS_MS 150
#define UNCERTAINTY_SCALE 10.0f
#define UNCERTAINTY_SYMMETRY_CAP 0.0f
#define ESTIMATE_FLOOR_KBPS 0.0f
class BitrateEstimator {
public:
@IMelker
IMelker / svn_monit.py
Created December 8, 2022 14:46
SVN updates monitor to discord weboohook
from time import sleep
import requests
import os.path
import sys
import pprint
import svn.local
import svn.remote
@IMelker
IMelker / download_unpack_rpm.sh
Last active January 11, 2022 08:38
Download rpm of exact version from yum and unpack it
#!/bin/bash
BINARY=$1
VER=$2
echo "Find ${BINARY} package with version ${VER}"
RPM_VER=`yum -v list ${BINARY} --show-duplicates | grep ${VER} | grep -oP "${VER}-\w{40}"`
echo "Founded: ${RPM_VER}"
echo "Downloading rpm ${BINARY} with version ${VER}"
@IMelker
IMelker / scope_exec.hpp
Last active May 17, 2021 06:39
RAI Initializer for C style inits
#ifndef SCOPEEXEC_H_
#define SCOPEEXEC_H_
#include <type_traits>
template <typename OnCreate, typename OnExit, class Enable = void>
class ScopeExec {
using OnCreateResultType = typename std::result_of_t<OnCreate(void)>;
public:
explicit ScopeExec(OnCreate onCreate, OnExit onExit)
@IMelker
IMelker / currenttime.hpp
Last active October 22, 2020 08:42
Get current time since epoch
#include <chrono>
#include <iomanip>
template <typename Clock>
class CurrentTime
{
template<struct tm* represent(const time_t *)>
static std::string utc() {
using namespace std::chrono;
auto timer = Clock::to_time_t(Clock::now());
@IMelker
IMelker / ObjectCounter.h
Created September 23, 2020 08:52
[Cpp] Class counter for object instances by inheritance(gcc)
//
// Created by imelker on 23.09.2020.
//
#ifndef OBJECTCOUNTER_H_
#define OBJECTCOUNTER_H_
#include <cstdio>
#define USE_COUNTER
@IMelker
IMelker / usr_local_tar
Created September 22, 2020 11:41
This is workaround for faster CLion file transfer in context of remote host
#!/bin/bash
#
# This is workaround for faster CLion file transfer in context of remote host
#
excludes=()
[[ $PWD =~ cmake-build- ]] && excludes=('--exclude=*.o' '--exclude=./bin' '--exclude=./lib')
first="$1"
@IMelker
IMelker / hidden_friend_idiom.cpp
Created July 13, 2020 11:28
Hidden friend idiom
namespace N {
class MyType {
Mytype& operator+=(const MyType&);
void print(std::ostream&);
void swap(MyType&) noexcept;
friend MyType operator+(MyType a, const MyType& b) {
a += b;
return a;
}
@IMelker
IMelker / ScopePrinter.cpp
Last active April 14, 2020 10:00
ScopePrinter to exchange printf and make it multithread
#include<string>
#include<iostream>
class ScopePrinter {
public:
template<typename STR>
explicit ScopePrinter(STR&& init, std::ostream& stream = std::cout)
: stream(stream),
msg(std::forward<STR>(init)) {
msg.append(":\t");
@IMelker
IMelker / cpp_tricks.cpp
Last active August 18, 2020 07:25
Cpp Tricks
// determining array size
template <typename T, auto N>
char (&ArraySizeHelper(T (&array)[N]))[N];
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
// convert defined value to string
#define expect(expr) if(!expr) cerr << "Assertion " << #expr \
" failed at " << __FILE__ << ":" << __LINE__ << endl;
#define stringify(x) #x