Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / splitRange.cpp
Created January 16, 2022 17:22
Evenly splits the values range for load balancing CPU cores
#include <iostream>
#include <utility>
#include <vector>
// Равномерно разделяет диапазон значения
// Для балансировки нагрузки на ядра CPU
std::vector<std::pair<int, int>>
splitRange(int from, int to, uint threads) noexcept
{
std::vector<std::pair<int, int>> pairs;
@valmat
valmat / entropy_benchmark.cpp
Created February 8, 2022 11:32
Entropies benchmark
#include <iostream>
#include <cmath>
#include <chrono>
struct BenchResult
{
std::chrono::nanoseconds duration;
double sum;
};
@valmat
valmat / fixdell
Last active April 21, 2022 06:48
Fix DELL freezes
#!/bin/bash
### BEGIN INIT INFO
# Provides: fixdell
# Required-Start: $local_fs $syslog $named
# Required-Stop: $local_fs $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Fix DELL freezes
# Description: startup script for Fix DELL freezes
### END INIT INFO
@valmat
valmat / proxy.c
Created December 1, 2022 10:14
Simple and fast async libevent tcp proxy
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <event2/bufferevent.h>
#include <event2/buffer.h>
#include <event2/listener.h>
#include <event2/util.h>
@valmat
valmat / change_owner.c
Created December 1, 2022 12:10
function to change process owner (if required)
#include <unistd.h>
// true if current user is not root
// or true if owner changing is not required (targ_uid == 0)
// or true if current user is root and uid changed
// false otherwise (owner changing was unsuccessful)
bool change_owner(unsigned int targ_uid) noexcept
{
return
(0u != getuid()) || // made sure that src_uid == 0 (source is root)
@valmat
valmat / gitai.sh
Last active December 11, 2024 17:13
AI git commit filler
#!/bin/env bash
set -e
model="gpt-4o";
temperature=0.8;
prompt="Below is the output of \`git diff HEAD\`."`
`"\nPlease provide a perfect git commit message."`
`"\nAlways use an emoji as the first character. Use emojis in the message text when appropriate."`
@valmat
valmat / gitaitag.sh
Last active December 11, 2024 17:14
Automatically creates a new tag and AI generated description for it
#!/bin/env bash
set -e
model="gpt-4o"
temperature=0.8
prompt="Below is the output of \`git log <latest_tag>..HEAD\`."`
`"\nPlease provide a perfect tag message."`
`"\nUse emojis in the message text when appropriate. Use past tense."`