Skip to content

Instantly share code, notes, and snippets.

@jlschrag
jlschrag / .cifscredentials
Last active July 19, 2022 19:55
Permanently Mapping a Windows Share On Linux
username=myusername
password=mysupersecretpassword
void BetterApproach()
{
{
shared_ptr<TooManyResponsibilities> root(new TooManyResponsibilities());
{
shared_ptr<Responsibility1> first = static_pointer_cast<Responsibility1>(root);
{
shared_ptr<Responsibility2> second = static_pointer_cast<Responsibility2>(root);
$val = (Get-ItemProperty -path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize').AppsUseLightTheme
$newval = -Not $val
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name AppsUseLightTheme -Value $newval
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme -Value $newval
@jlschrag
jlschrag / OOApproach_Caller.h
Last active January 6, 2021 16:03
Designing a C interface for complex types
auto resort = ExternalInterface_GetSkiResort("Tahoe");
auto blackRuns = resort.GetRunsByDifficulty(resort.Resort, SkiRunDifficultyRating::Black);
//Process the runs list
resort.Destroy(resort.Resort);
blackRuns.Destroy(blackRuns.Collection);
@jlschrag
jlschrag / CMakeLists.txt (for SharedLib project)
Last active June 26, 2020 18:10
Passing an interface from a Linux shared library
cmake_minimum_required(VERSION 3.13) #3.13 was what I had on my WSL install.
project(SharedLib VERSION 0)
add_library(SharedLib SHARED "")
set_target_properties(SharedLib PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(SharedLib PROPERTIES SOVERSION 1) #API Version
target_sources(SharedLib
PUBLIC
SharedLib.h
@jlschrag
jlschrag / CMakeLists.txt (for SharedLib project)
Created June 11, 2020 16:14
HelloWorld from a Linux shared library
cmake_minimum_required(VERSION 3.13) #3.13 was what I had on my WSL install.
project(SharedLib VERSION 0)
add_library(SharedLib SHARED "")
set_target_properties(SharedLib PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties(SharedLib PROPERTIES SOVERSION 1) #API Version
target_sources(SharedLib
PUBLIC
SharedLib.h

#define's in C++ code are a terrible way to define collections, but they are commonplace in legacy code. After a few years of refining my approach, this is what I have come up with to replace them.

I recently had need for a C++ collection which could be accessed with multiple keys. Specifically, I had an object that I wanted to look up either by name or id (in O(1) time). One way to do this is to create two unordered_maps – one keyed by id and another by name, but that is error-prone. I ended up finding a boost class which will do this. It took me a while get it working, so I thought I would share the result.