Skip to content

Instantly share code, notes, and snippets.

@valmat
valmat / safe_amqpcpp.h
Created April 9, 2024 20:06
Suppress warnings for a library (example)
#pragma once
// Suppress warnings for AMQP-CPP
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-parameter"
#pragma clang diagnostic ignored "-Wclass-conversion"
#pragma clang diagnostic ignored "-Wdeprecated-copy"
#include <amqpcpp.h>
#include <amqpcpp/libev.h>
@valmat
valmat / gitaitag.sh
Last active February 29, 2024 13:08
Automatically creates a new tag and AI generated description for it
#!/bin/env bash
set -e
model="gpt-4-turbo-preview";
temperature=0.8;
prompt="Here is the output of \`git log <latest_tag>..HEAD\`. Please provide the perfect tag message."`
`" Use emjoi if it is possible. Use past tense. "`
`"Provide a message ready for direct substitution "`
@valmat
valmat / gitai.sh
Last active February 29, 2024 13:09
AI git commit filler
#!/bin/env bash
set -e
model="gpt-4-turbo-preview";
temperature=0.8;
prompt="Here is the output of \`git diff HEAD\`. Please provide the perfect commit message."`
`" Use emjoi if it is possible. Use past tense in the title. "`
`"(# If there is an error in the code, report it in the comments to the commit please)."
@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 / 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 / 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 / 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 / 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 / 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) ;}