Skip to content

Instantly share code, notes, and snippets.

@IMelker
IMelker / dump_bytes.cpp
Last active May 6, 2021 17:29
Dump bytes to cstring
#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;
@IMelker
IMelker / Nearest upper power of two [cpp]
Last active September 30, 2019 14:55
Get nearest upper power of two to current number
long NUP2(long x) {
x--;
for (int p=1; p<32; p<<=1) x |= (x >> p);
return ++x;
}
@IMelker
IMelker / RandomWrapper class [cpp]
Last active August 20, 2019 09:17
RandomWrapper
#include <random>
template<typename T>
class RandomWrapper
{
public:
RandomWrapper() : data(dist(rng)) {
}
operator T() { return data; }
@IMelker
IMelker / VMBox Centos 7 prepare for install VirtualBox Guest Additions [prepare.sh]
Last active June 15, 2019 14:31
Centos7 VirtualBox Guest Additions installation
#!/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
# ------------------------------------------------------------
@IMelker
IMelker / code_format.sh [recursive clang-format]
Last active July 26, 2019 08:45
clang-format wrapper for multifile ussage [cpp]
#!/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
# ------------------------------------------------------------
@IMelker
IMelker / [DEB] Reconfigure all pacakges. [reconfigure.sh]
Last active May 18, 2023 09:41
Reconfiguare all installed packages
#!/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
# ------------------------------------------------------------