Skip to content

Instantly share code, notes, and snippets.

View boki1's full-sized avatar
🧐

Kristiyan Stoimenov boki1

🧐
View GitHub Profile
@boki1
boki1 / c.sh
Last active May 7, 2024 07:48
Convert audio files to mp3
#/bin/bash
# https://unix.stackexchange.com/questions/9496/looping-through-files-with-spaces-in-the-names
find . -type f -name '*.wav' -exec sh -c '
for file do
echo "$file"
ffmpeg -i "$file" -acodec mp3 "${file%.*}.mp3"
done
' exec-sh {} +
@boki1
boki1 / bpt2dec.c
Created November 1, 2023 00:06
Convert a number from base power of 2 to decimal.
#include <stddef.h>
#include <stdio.h>
/* Base power of 2 to decimal */
static unsigned bpt2dec(unsigned x, size_t mask) {
int indec = 0;
const int bits = __builtin_popcount(mask);
for (int i = 0; x != 0; ++i, x >>= bits)
indec += ((x & mask) << (i * bits));
return indec;
@boki1
boki1 / rootsofunity.tex
Created September 22, 2023 12:40
Draw a diagram illustrating roots of unity in the case of C_n
\begin{tikzpicture}
\coordinate (center) at (0, 0);
\def\radius{2cm}
\def\n{5}
\pgfmathsetmacro\angle{360/\n}
\pgfmathsetmacro\startangle{90}
\foreach \i in {0,...,4} {
\coordinate (point\i) at ({\startangle+\angle*\i}:\radius);
\coordinate (label\i) at ({\startangle+\angle*\i}:\radius+0.25cm);
@boki1
boki1 / cpp_syntax_is_great.cpp
Created July 25, 2023 16:48
Since c++23 supports attributes on lambdas, @lefticus came up with this real beautiful snippet of C++.
///
/// Valid syntax for whatever reason :D.
/// See https://www.youtube.com/watch?v=YlmxNJnone0 for details (if you dare).
///
int main() {
auto l = [][[]]([[]] auto) [[]] { return 42; };
}
@boki1
boki1 / fun.cpp
Created July 19, 2023 16:27
Pass a function as an argument.
#include <iostream>
#include <functional>
#include <concepts>
// Problem: Pass a function as an argument
// 1. function pointer (old & C-style)
// Ugly but somewhat nice as it is very simple. See https://cdecl.org
// BTW: https://www.youtube.com/watch?v=6eX9gPithBo
@boki1
boki1 / pdf_page_unsplit.py
Created May 13, 2023 13:19
Given a PDF file which contains scanned "split-page" views of each pair of pages, this script helps you reformat the document into one which contains each page as a separate one.
# MIT License, Kristiyan Stoimenov 2023
#
# Use `--help` for a nice overview of the options.
import PyPDF2
import argparse
argparser = argparse.ArgumentParser()
argparser.add_argument("-o", "--output_file", help="output file")
argparser.add_argument("-i", "--input_file", help="input file")
@boki1
boki1 / test.c
Created February 5, 2023 22:54
Peculiar C snippets - taken from this [Advanced C presentation](https://youtu.be/w3_e9vZj7D8)
// Compiler explorer: https://godbolt.org/z/dnjeMhzv1
#include <stdio.h>
void array_index() {
int x = 3;
int a[5];
a[x] = 0;
if (x >= 5)
printf("Hello world\n");
#!/bin/sh
project_name="project_name"
out_dir=build/out
usage() {
echo "Bad usage: ./build/abc.sh [build|test|clean|format]"
}
make_build() {
@boki1
boki1 / jpg_to_pdf.py
Created May 27, 2022 15:08
Create PDFs from multiple images
from PIL import Image
from glob import glob
from argparse import ArgumentParser
from colorama import Fore, Style
extension='jpg'
path='./'
out=f'{path}/slides.pdf'
parser = ArgumentParser(description='Convert multiple images to a pdf')
@boki1
boki1 / CMakeLists.txt
Created September 16, 2021 11:21
C++20 Modules tryout
cmake_minimum_required(VERSION 3.19) # Lower versions should also be supported
project(cpp20-modules)
# Add target to build iostream module
add_custom_target(std_modules ALL
COMMAND ${CMAKE_COMMAND} -E echo "Building standard library modules"
COMMAND g++ -fmodules-ts -std=c++20 -c -x c++-system-header iostream
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)