Skip to content

Instantly share code, notes, and snippets.

View mhrstmnn's full-sized avatar

Michael Horstmann mhrstmnn

View GitHub Profile
@mhrstmnn
mhrstmnn / stow_directories.sh
Created May 5, 2024 20:54
Zsh script to stow directories in a directory
#!/bin/zsh
# ANSI color codes
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
for directory in */; do
directory="${directory%/}"
echo -n "Stowing $directory ... "
@mhrstmnn
mhrstmnn / find_toml_files.py
Last active April 13, 2024 10:45
A simple script to find TOML files recursively
#!/usr/bin/env python3
import os
import sys
def find_toml_files() -> list[str]:
def find_toml_files_recursively(directory_path: str, found_toml_files: list[str]) -> None:
def get_directory_entries(directory_path: str) -> list[str]:
return list(map(lambda entry: os.path.join(directory_path, entry),
@mhrstmnn
mhrstmnn / main.cpp
Last active April 19, 2024 13:03
Simple method to output CLI arguments in C++
#include <iostream>
void printArgs(const int argc, const char *argv[])
{
std::cout << "argc: " << argc << "\n\n"
<< "argv:\n";
for (unsigned int i{}; i < static_cast<unsigned int>(argc); ++i)
std::cout << "- " << argv[i] << '\n';
}
@mhrstmnn
mhrstmnn / Program.cs
Last active April 13, 2024 12:22
Simple method to output CLI arguments in C#
class Program
{
private static void PrintArgs(string[] args)
{
Console.WriteLine("argc: " + args.Length);
if (args.Length > 0)
{
Console.WriteLine("\nargs:");
Console.WriteLine("- " + string.Join("\n- ", args));
}
@mhrstmnn
mhrstmnn / new_script.sh
Last active April 13, 2024 12:21
A script to create new scripts
#!/bin/zsh
OUTPUT='#!/bin/zsh\n\n# TODO'
FILENAME='empty_script.sh'
if [ $# -ne 0 ]; then
if [[ "$*" == *.* ]]; then
FILENAME="$*"
else
FILENAME="$*.sh"
@mhrstmnn
mhrstmnn / .editorconfig
Last active April 13, 2024 12:10
Template for new EditorConfig configurations
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
@mhrstmnn
mhrstmnn / init.lua
Last active April 24, 2024 19:37
Template for new Neovim configurations
-- help relativenumber
vim.cmd [[set relativenumber]]
-- help restore-cursor
-- help last-position-jump
vim.cmd [[autocmd BufRead * autocmd FileType <buffer> ++once
\ if &ft !~# 'commit\|rebase' && line("'\"") > 1 && line("'\"") <= line("$") | exe 'normal! g`"' | endif]]
@mhrstmnn
mhrstmnn / pip_install.sh
Last active February 14, 2024 15:53
Install the packages from the requirements.txt with pip in a virtual environment
#!/bin/zsh
python3 -m venv venv
source ./venv/bin/activate
python3 -m pip install -r requirements.txt
@mhrstmnn
mhrstmnn / examples.ts
Created July 19, 2023 01:51
Task queue developed to run with Deno
import { TaskQueue } from './task_queue.ts'
const queue = new TaskQueue({
rateLimiter: {
interval: 'second',
tasksPerInterval: 2,
},
})
// Example with await
function padNumber(n: number): string {
return n.toString().padStart(2, '0')
}
function formatDate(
date: Date,
offset?: Partial<{
year: number
month: number
day: number