Skip to content

Instantly share code, notes, and snippets.

View moeryomenko's full-sized avatar
🏠
work at home

Maxim Eryomenko moeryomenko

🏠
work at home
View GitHub Profile
@moeryomenko
moeryomenko / Makefile
Created March 28, 2023 06:06
Makefile with help command
.PHONY: help
help: ## Prints this help message
@echo "Commands:"
@grep -F -h '##' $(MAKEFILE_LIST) \
| grep -F -v fgrep \
| sort \
| grep -E '^[a-zA-Z_-]+:.*?## .*$$' \
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-30s\033[0m %s\n", $$1, $$2}'
@moeryomenko
moeryomenko / main.go
Created August 1, 2022 20:02
durable receiving
package main
import (
"context"
"fmt"
"time"
)
func withinDuration(duration time.Duration, stream <-chan string) (<-chan struct{}, <-chan string) {
stopToken := make(chan struct{}, 1)
@moeryomenko
moeryomenko / mysql5.if_not_exists.sql
Created December 16, 2021 15:12
mysql5 if not exists emulation
--- if not exists index
SET @dbname = DATABASE();
SET @tablename = "TABLENAME";
SET @indexname = "INDEXNAME";
SET @preparedStatement =
(SELECT IF (EXISTS
(SELECT COUNT(*)
FROM information_schema.statistics
WHERE (table_schema = @dbname)
AND (table_name = @tablename)
@moeryomenko
moeryomenko / Dockerfile
Last active June 7, 2022 11:07
Fast docker build
# use DOCKER_BUILDKIT=1
FROM golang:1.17.3-alpine3.14 AS build
ENV GO111MODULE on
# 1. Precompile the entire go standard library into the first Docker cache layer: useful for other projects too!
RUN --mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=linux go install -v -installsuffix cgo -a std
WORKDIR /src
From dee28179a8d0e01e2ec4e2562014364162ad2e92 Mon Sep 17 00:00:00 2001
From: Maxim Eryomenko <moeryomenko@gmail.com>
Date: Wed, 2 Jun 2021 13:50:44 +0300
Subject: [PATCH] convert string to arithmetic type if possible
Resolves: https://stackoverflow.com/q/67793080/7821330
Signed-off-by: Maxim Eryomenko <moeryomenko@gmail.com>
---
.../nlohmann/detail/conversions/from_json.hpp | 220 ++++++++----------
static const unsigned values_group_1 = (1 << 1) | (1 << 2) | (1 << 3);
static const unsigned values_group_2 = (1 << 4) | (1 << 5) | (1 << 6);
static const unsigned values_group_3 = (1 << 7) | (1 << 8) | (1 << 9);
if ((1 << value_to_check) & values_group_1) {
// You found a match for group 1
}
if ((1 << value_to_check) & values_group_2) {
// You found a match for group 2
}
if ((1 << value_to_check) & values_group_3) {
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
struct node {
int value;
struct node* next;
};
@moeryomenko
moeryomenko / CMakeLists.txt
Last active April 21, 2021 15:43
Common cmake script
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(<project-name> CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# need for clangd.
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# install module that speeds up the build process.
@moeryomenko
moeryomenko / bash
Last active May 3, 2021 12:42
cmake build command with export compile commands
$ cmake -GNinja -H. -Bbuild -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER_LAUNCHER='/usr/bin/ccache' -DCMAKE_CXX_COMPILER_LAUNCHER='/usr/bin/ccache'
@moeryomenko
moeryomenko / parse.sh
Created March 28, 2021 16:02
Bash simple yaml parser
#!/bin/bash
function parse_yaml {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\):|\1|" \
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;