Skip to content

Instantly share code, notes, and snippets.


Igor Melker IMelker

  • Voximplant
  • Moscow
View GitHub Profile
IMelker /
Last active Jan 11, 2022
Download rpm of exact version from yum and unpack it
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 / scope_exec.hpp
Last active May 17, 2021
RAI Initializer for C style inits
View scope_exec.hpp
#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)>;
explicit ScopeExec(OnCreate onCreate, OnExit onExit)
IMelker / currenttime.hpp
Last active Oct 22, 2020
Get current time since epoch
View currenttime.hpp
#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 / ObjectCounter.h
Created Sep 23, 2020
[Cpp] Class counter for object instances by inheritance(gcc)
View ObjectCounter.h
// Created by imelker on 23.09.2020.
#include <cstdio>
IMelker / usr_local_tar
Created Sep 22, 2020
This is workaround for faster CLion file transfer in context of remote host
View usr_local_tar
# This is workaround for faster CLion file transfer in context of remote host
[[ $PWD =~ cmake-build- ]] && excludes=('--exclude=*.o' '--exclude=./bin' '--exclude=./lib')
View hidden_friend_idiom.cpp
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 / ScopePrinter.cpp
Last active Apr 14, 2020
ScopePrinter to exchange printf and make it multithread
View ScopePrinter.cpp
class ScopePrinter {
template<typename STR>
explicit ScopePrinter(STR&& init, std::ostream& stream = std::cout)
: stream(stream),
msg(std::forward<STR>(init)) {
View cpp_tricks.cpp
// 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
IMelker / dump_bytes.cpp
Last active May 6, 2021
Dump bytes to cstring
View dump_bytes.cpp
#include <cstring>
#include <cstdio>
void dump_bytes(const unsigned char * data, int len, char *outBuf) {
sprintf(outBuf, "%d bytes:\n", len);
char * tmp=outBuf + strlen(outBuf);
for (int j=0; j<len; j++) {
if (j % 16 == 0) {
sprintf(tmp, "%04X:", j);
IMelker / Nearest upper power of two [cpp]
Last active Sep 30, 2019
Get nearest upper power of two to current number
View Nearest upper power of two [cpp]
long NUP2(long x) {
for (int p=1; p<32; p<<=1) x |= (x >> p);
return ++x;