Skip to content

Instantly share code, notes, and snippets.

Avatar

Igor Melker IMelker

  • Voximplant
  • Moscow
View GitHub Profile
@IMelker
IMelker / [DEB] Reconfigure all pacakges. [reconfigure.sh]
Last active Sep 30, 2019
Reconfiguare all installed packages
View [DEB] Reconfigure all pacakges. [reconfigure.sh]
#!/bin/bash
# ------------------------------------------------------------
# Reconfiguare all *.deb installed packages
# Run dpkg-reconfigure for all dpkg -l
#
# USAGE insert next to terminal or run as sh script
#
# Be careful reconfiguration can broke your system
# ------------------------------------------------------------
@IMelker
IMelker / code_format.sh [recursive clang-format]
Last active Jul 26, 2019
clang-format wrapper for multifile ussage [cpp]
View code_format.sh [recursive clang-format]
#!/bin/bash
# ------------------------------------------------------------
# Recursive cpp code formatter based on clang-format
# For base work there is you need to have .clang-format file
#
# USAGE code_format.sh [clang-format-options] [<file|dir> ...]
#
# clang-format-options passes through to clang-format
# ------------------------------------------------------------
View VMBox Centos 7 prepare for install VirtualBox Guest Additions [prepare.sh]
#!/bin/bash
# ------------------------------------------------------------
# Centos7 VirtualBox Guest Additions installation
# Update kernel headers and install requirements for it
#
# USAGE sudo prepare.sh
#
# sudo requires for installation, export KERNEL_DIR and reboot
# ------------------------------------------------------------
View RandomWrapper class [cpp]
#include <random>
template<typename T>
class RandomWrapper
{
public:
RandomWrapper() : data(dist(rng)) {
}
operator T() { return data; }
@IMelker
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) {
x--;
for (int p=1; p<32; p<<=1) x |= (x >> p);
return ++x;
}
@IMelker
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);
tmp+=5;
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
IMelker / ScopePrinter.cpp
Last active Apr 14, 2020
ScopePrinter to exchange printf and make it multithread
View ScopePrinter.cpp
#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");
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
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
#!/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"