Skip to content

Instantly share code, notes, and snippets.

@valmat
valmat / GenericMakefile.mk
Created December 14, 2021 07:16 — forked from natanaeljr/GenericMakefile.mk
Simple generic makefile example to start a project quickly. Can: select C or C++ compiler automatically, identify multiple extentions, detect auto-dependencies and compile modified files only, etc. Various modifiable settings.
PROJECT := $(notdir $(CURDIR))
EXCECUTABLE = $(BUILDDIR)/$(PROJECT)
# Directories specification
SRCDIRS := src
INCDIRS := include
BUILDDIR := build
# @note: to add another source extension, add to herer AND make sure to
# write the " $(BUILDDIR)/%.o: %.ext " rule for this extention in order to work
@valmat
valmat / if_constexpr_type.cpp
Created September 15, 2021 18:33
if constexpr to switch type
// if constexpr to switch type
//
template<uint8_t N>
struct _buf_type
{
static_assert(N > 0, "Buffer must be more then 0");
static_assert(N <= 64, "Maximum buffer size is 64");
constexpr static auto _i2t()
{
if constexpr (N <= 8 ) {return uint8_t(0) ;}
@valmat
valmat / find_mt.d
Last active August 25, 2022 13:27
Multithreading find and execute
#!/usr/bin/rdmd --shebang= -I. -w -debug -g
//
// multithreading find and execute
//
/*
ldc2 -O3 -dw -release -w -boundscheck=off -fvisibility=hidden -c find_mt.d -of=find_mt.o && \
ldc2 -O3 -dw -release -w -link-defaultlib-shared=false -L-l:libphobos2-ldc.a -L-l:libdruntime-ldc.a -L-l:libz.a find_mt.o -of=find_mt && \
strip --strip-all find_mt && \
@valmat
valmat / get_tz.sh
Created October 2, 2019 11:07
Get all time zones and their offsets in Linux.
#!/bin/bash
for tz in $(timedatectl list-timezones | grep -v 'UTC')
do
gmtoff=$(zdump -v "$tz" | grep 'gmtoff' | tail -n1 | grep -oE "[^ ]+$")
tz_offset="${gmtoff:7}"
if [[ "${gmtoff:0:7}" == "gmtoff=" ]]; then
echo "$tz;$tz_offset"
fi
@valmat
valmat / proxy.md
Created April 14, 2018 08:34
proxy

Проверено на 5 баксовом тарифе DigitalOcean


Создаём proxy пользователя для аутентификации по паролю:

useradd -d /dev/null teleg
passwd teleg
@valmat
valmat / double_static_polymorphism.cpp
Created March 27, 2018 19:10
CRTP. Double static polymorphism
//
// CRTP. Double static polymorphism
//
// g++ -std=c++14 1.cpp && ./a.out
#include <iostream>
#include <string>
using std::cout;
@valmat
valmat / vlm.utils.destructing.d
Last active June 1, 2020 18:20
variable destructuring; array to variables list; destructuring assign. Traversable, Tuple
//
// May destructing variables for itarable types and tuples
//
module vlm.utils.destructing;
import std.range : empty, popFront, front;
import std.traits : isIterable;
import std.typecons : Tuple, tuple, isTuple;
import std.functional : forward;
@valmat
valmat / private_constructor_eb.cpp
Created February 16, 2018 17:19
Solving prblem with emplace_back and private constructor
#include <vector>
#include <iostream>
class A
{
private:
struct private_key {};
// private constructor
A(int a) :
a(a)
@valmat
valmat / StringManip.d
Last active February 20, 2018 07:04
variable destructuring; array to variables list; destructuring assign.
module StringManip;
import std.range : empty, popFront, front;
auto destr(Arg0, Args...)(ref Arg0 arg0, ref Args args)
{
return DestrInstance!(Arg0, Args.length+1)(arg0, args);
}
@valmat
valmat / try-haskell.hs
Created November 14, 2016 17:32
try haskell
join :: Char -> [String] -> String
join _ [] = []
join _ [s] = s
join gl arr =
head arr ++ gl : joingl (tail arr)
where
joingl = join gl
putStrLn (join ':' ["str1", "str2", "str3"])