Skip to content

Instantly share code, notes, and snippets.

View dk949's full-sized avatar

David K dk949

View GitHub Profile
#ifndef UT_ERR
#define UT_ERR
#include <concepts>
#include <type_traits>
#if __cplusplus < 202'302L
# error this file has to be compiled with at least C++23
#endif
#include <expected>
@dk949
dk949 / overload.hpp
Last active June 8, 2025 23:17
Creates a c++ function object merging several other function objects as an overload set
#ifndef UT_OVERLOAD
#define UT_OVERLOAD
#if __cplusplus < 201'703L
# error this file has to be compiled with at least C++17
#endif
namespace ut {
/**
@dk949
dk949 / asis.hpp
Last active June 8, 2025 23:04
Provides a more convenient way to work with different kinds of dynamically polymorphic values
#ifndef UT_ASIS
#define UT_ASIS
#include <memory>
#include <type_traits>
#if __cplusplus < 202'002L
# error this file has to be compiled with at least C++20
#endif
namespace ut {
@dk949
dk949 / DateTime.zig
Created March 18, 2025 01:40
A very basic utility to manage date and time in UTC timezone
//! A very basic utility to manage date and time in UTC timezone.
//!
//! Usage:
//!
//! ```zig
//! // The following examples assume that the current date and time is 25th May 1977, at 08:48 PM
//! const now = DateTime.now();
//! std.debug.print("{}\n", .{now}); // 1977-05-25 20:48:00
//! std.debug.print("{%d %B %Y at %I}:{%M %p}\n", .{ now, now }); // 25 May 1977 at 08:48 PM
//! // NOTE: the format string has to be split in two, because `:` is a special character in fmt
#ifndef UT_CHECK_HPP
#define UT_CHECK_HPP
#if __cplusplus < 201'103L
# error this file has to be compiled with at least C++11
#endif
/// Class for checking when a c++ object is constructed, copied, moved from or destructed
/* Usage:
#ifndef UT_CONSTEXPR_HASH_HPP
#define UT_CONSTEXPR_HASH_HPP
#include <string_view>
#if __cplusplus < 201'703L
# error this file has to be compiled with at least C++17
#endif
/* Usage:
*
#ifndef UT_ADD_NOEXCEPT_H
#define UT_ADD_NOEXCEPT_H
#if __cplusplus < 201'703L
# error this file has to be compiled with at least C++17
#endif
namespace ut {
/*
* Add noexcept to function type
@dk949
dk949 / change_observer.hpp
Last active June 8, 2025 23:08
A C++ wrapper class that invokes callbacks when it's held value changes
#ifndef UT_CHANGE_OBSERVER
#define UT_CHANGE_OBSERVER
#if __cplusplus < 202'002L
# error this file has to be compiled with at least C++20
#endif
#include <functional>
#include <type_traits>
#include <vector>
@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