Skip to content

Instantly share code, notes, and snippets.

View miss-programgamer's full-sized avatar

ProgramGamer miss-programgamer

View GitHub Profile
@miss-programgamer
miss-programgamer / dictionary.cpp
Created December 20, 2025 01:18
An implementation of a dictionary type in C++ as an alias of std::unordered_map which uses a custom hash functor. This hash uses a trait type to tag specific combinations of types as transparent so that map lookups can happen using heterogenous types (like std::string and std::string_view, for instance).
#include <string>
#include <string_view>
#include <unordered_map>
template<typename T, typename = void>
struct KeyTraits {};
template<>
struct KeyTraits<std::string, std::string_view>
{
@miss-programgamer
miss-programgamer / replaceYall.js
Created February 28, 2025 04:17
Perform a search-and-replace operation on a string based on the key/value pairs of an object.
/**
* Search-and-replaces the given text based on the key/value pairs of an object.
* @param {string} text - Text to search and replace.
* @param {object} object - Replacee/replacement key/value pairs.
* @returns {string} Text after having pieces replaced.
*/
function replaceYall(text, object) {
return Object.keys(object).reduce((text, key) => {
return text.replaceAll(key, object[key]);
}, text);
@miss-programgamer
miss-programgamer / main.cpp
Last active November 17, 2020 08:29
volatile qualifier ignores virtual pointer section of class instance
/*
Author: Miss Programgamer
This is an example program that illustrates that some compilers (such as vc++ and g++)
ommit volatility for the vptr part of classes. While I do not know the exact wording
of the standard, I know that the intent of the "volatile" qualifier is to make the
compiler ommit various caching optimisations and read a value each time it is needed,
as the qualifier indicates that memory may be changed unpredictably. However, this
principle is not honored for virtual table pointers, at least for the compilers
listed above.