Skip to content

Instantly share code, notes, and snippets.

@bilbothebaggins
bilbothebaggins / callback.cpp
Created February 11, 2023 10:00
C++ Null-Object vs Pointer Callback
#include <iostream>
struct HelloData {
int i = 0;
const char* s = "";
};
struct CallbackBase {
virtual ~CallbackBase() = default;
virtual void Hello(HelloData const& d) = 0;
@bilbothebaggins
bilbothebaggins / query_process1.cpp
Created January 11, 2023 13:37
Query Proces Information Full Path
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#include <TlHelp32.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
int main() {
@bilbothebaggins
bilbothebaggins / main.cpp
Last active February 9, 2022 14:52
C++ Floating Point Double 655
#include <cstdio>
#include <string>
__declspec(noinline) double get_delta(double lhs, double rhs) {
return lhs - rhs;
}
void print_dbl(std::string const& what, double val) {
const int dig14 = DBL_DIG - 1;
printf("'%s'@%d: %.*e\n", what.c_str(), dig14, dig14, val);
@bilbothebaggins
bilbothebaggins / ConvertTo-ArgvQuoteForPoSh.ps1
Last active May 7, 2023 16:25
Powershell V5 (and C# Code) to allow escaping native command arguments
function Get-NeedsArgvQuote {
<#
.DESCRIPTION Fix up our argument string for the insane CommandLineToArgvW rules
.LINK https://docs.microsoft.com/en-us/archive/blogs/twistylittlepassagesallalike/everyone-quotes-command-line-arguments-the-wrong-way
#>
[CmdletBinding()]
param(
[Parameter(Position=0,Mandatory=1)][AllowEmptyString()][string]$arg
)
if ([System.String]::IsNullOrEmpty($arg)) {