Skip to content

Instantly share code, notes, and snippets.

View dk949's full-sized avatar

David K dk949

View GitHub Profile
@dk949
dk949 / mtime-to-exif.py
Created February 17, 2025 05:39
A small script to fix the datetime of jpg files in a directory. It copies the exif datetime to the file's mtime and vice versa. This can fix various importing issues with photo management software (e.g. Google photos).
"""
A small script to fix the datetime of jpg files in a directory.
It copies the exif datetime to the file's mtime and vice versa.
This can fix various importing issues with photo management software (e.g. Google photos).
NOTE: This script uses the piexif library to read and write exif data, you will need to install it.
NOTE 2: This script will overwrite the mtime of the files. If you use the
@dk949
dk949 / copy_traits.hpp
Last active June 8, 2025 23:11
Copies const, volatile or reference qualifiers from one type to another
#ifndef UT_COPY_TRAITS
#define UT_COPY_TRAITS
#if __cplusplus < 202'002L
# error this file has to be compiled with at least C++20
#endif
/**
* Usage:
* std >= c++20
@dk949
dk949 / inspect.lua
Last active February 25, 2025 10:51
Print any lua value as a readable string
---Inspect a value
---
---Converts nil, boolean, number, string or table to string
---Any other type is converted with `tostring`.
---
---List-like tables are printed without their indices
---
---Usage:
---
---```lua
@dk949
dk949 / typecheck.py
Created September 13, 2024 20:23
Python decorator to do runtime typechecking based on function type annotations. See docstring for detaills
def typecheck(
func=None,
*,
check_return=False,
):
"""
Perform a runtime type check of the function arguments and (optionally) its
return type.
All annotated arguments and keyword arguments will be typechecked. Known
@dk949
dk949 / assert.hpp
Last active October 4, 2025 13:30
Various assertion macros and functions
#ifndef UT_ASSERT_
#define UT_ASSERT_
#if __cplusplus < 202'002L
# error this file has to be compiled with at least C++20
#endif
/** Usage:
* std >= C++20 (C++23)
*
@dk949
dk949 / trim.hpp
Last active June 8, 2025 23:26
Trim string_view. Using whitespace by default
#ifndef UT_TRIM
#define UT_TRIM
#if __cplusplus < 202'002L
# error this file has to be compiled with at least C++20
#endif
/** Usage:
* std >= C++20
* Simple string_stream trimming (trims whitespace by default)
@dk949
dk949 / get_notes.awk
Created May 23, 2024 18:17
Extract speaker notes from a pandoc markdown document
# Extract speaker notes (with related headings) from a pandoc markdown document
# Produces valid markdown which can be compiled with pandoc
# Headings are also separated by hrules
# Example usage:
# awk -f get_notes.awk your_source.md | pandoc -f markdown -o your_notes.pdf
## Find the closing div for the notes
@dk949
dk949 / pair.hpp
Last active June 8, 2025 23:19
std::pair alternative with extra features and no constructors
#ifndef UT_PAIR_HPP
#define UT_PAIR_HPP
#if __cplusplus < 202'002L
# error this file has to be compiled with at least C++20
#endif
// A std::pair replacement with no implicit (or any!) constructors.
// All conversions are done through either member functions or static functions
// Also you can use it in a range-based-for loop if the types of `first` and `second` are the same
@dk949
dk949 / realloc_unique_ptr.hpp
Last active June 8, 2025 23:24
realloc for unique_ptr
#ifndef UT_REALLOC_UNIQUE_PTR_HPP
#define UT_REALLOC_UNIQUE_PTR_HPP
#include <memory>
#include <utility>
#if __cplusplus < 201'703L
# error this file has to be compiled with at least C++17
#endif
@dk949
dk949 / sv_to_num.hpp
Last active June 8, 2025 23:25
Convenient string_view to number conversions
#ifndef UT_SV_TO_NUM_HPP
#define UT_SV_TO_NUM_HPP
#include <charconv>
#include <concepts>
#include <optional>
#include <string_view>
#if __cplusplus < 202002L
#error this file has to be compiled with at least C++20
#endif