Skip to content

Instantly share code, notes, and snippets.

View smourier's full-sized avatar

Simon Mourier smourier

View GitHub Profile
@smourier
smourier / NumberedNoWrappedTxtBooks.cs
Created March 30, 2025 05:45
Creates a numbered, unwrapped versions of .txt books (for the ones like in project gutenberg https://www.gutenberg.org/)
public static void Main(string[] args)
{
var path = @"C:\Users\bob\Downloads\AliceInWonderland.txt";
path = @"C:\Users\bob\Downloads\Frankenstein.txt";
path = @"C:\Users\bob\Downloads\MobyDick.txt";
var text = File.ReadAllText(path);
// add numbers in front of each line
var lines = text.Split(["\r\n", "\n"], StringSplitOptions.None);
var digits = Math.Floor(Math.Log10(lines.Length) + 1);
@smourier
smourier / addexif.cs
Created March 10, 2025 19:46
WinRT C# code that loads some file, and save it back with EXIF metadata
using System;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Graphics.Imaging;
using Windows.Storage;
public static async Task AddExifToFile()
{
// get an input file
var inputPath = @"d:\temp\tiger.png";
@smourier
smourier / installdocker.bat
Created February 27, 2025 09:25
installing docker & docker data somewhere custom
"Docker Desktop Installer.exe" install --accept-license --installation-dir=F:\Docker\Docker --wsl-default-data-root=F:\Docker\wsldata --hyper-v-default-data-root=F:\Docker\hvdata --windows-containers-default-data-root=F:\Docker\wincdata
@smourier
smourier / findaxcm.bat
Created February 14, 2025 14:54
Find appx packages that registers as Explorer's context menus
C:\Program Files\WindowsApps\findstr /S /Q:u fileExplorerContextMenus *.xml
@smourier
smourier / DropIndexes.sql
Created November 27, 2024 11:18
SQL to drop indexes for all tables in a schema
-- was adapted from https://www.brentozar.com/archive/2017/08/drop-indexes-fast which fails for some pks
CREATE OR ALTER PROCEDURE dbo.DropIndexes
@SchemaName NVARCHAR(255) = 'dbo',
@TableName NVARCHAR(255) = NULL,
@WhatToDrop VARCHAR(10) = 'Everything',
@ExceptIndexNames NVARCHAR(MAX) = NULL
AS
BEGIN
SET NOCOUNT ON;
@smourier
smourier / EnumerateDllExports.cs
Created November 6, 2024 18:17
Enumerate Dll Exports in C#
public static class BinaryUtilities
{
[DllImport("dbghelp", CharSet = CharSet.Unicode)]
private static extern bool SymInitialize(nint hProcess, string? userSearchPath, bool fInvadeProcess);
[DllImport("dbghelp", CharSet = CharSet.Unicode)]
private static extern bool SymCleanup(nint hProcess);
[DllImport("dbghelp", CharSet = CharSet.Unicode)]
private static extern ulong SymLoadModuleEx(nint hProcess, nint hFile, string imageName, string? moduleName, long baseOfDll, int dllSize, nint data, int flags);
@smourier
smourier / GetProcAddress.cpp
Created September 27, 2024 06:44
GetProcAddress
extern "C" __declspec(dllimport) BOOL getCursorPos(LPPOINT);
extern "C" FARPROC __imp_getCursorPos = GetProcAddress(LoadLibrary(L"user32.dll"), "GetCursorPos");
int main()
{
POINT p{};
getCursorPos(&p);
return 0;
}
@smourier
smourier / nvmldxgi.cpp
Created September 17, 2024 16:34
dump DXGI & NVML PCI bus information
#include <windows.h>
#include <dxgi.h>
#include <D3dkmthk.h>
#include <stdio.h>
#include "nvml\include\nvml.h"
#pragma comment(lib, "nvml\\lib\\nvml.lib")
#pragma comment(lib, "dxgi.lib")
@smourier
smourier / OnDemandDataObject.cs
Created August 31, 2024 13:27
On-Demand IDataObject
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Windows.Forms;
namespace OnDemandDataObject;
@smourier
smourier / PrivateUwpRegistry.cpp
Created August 24, 2024 12:40
Update some (here photos) app's registry from outside the app itself.
#include <windows.h>
#include <userenv.h>
#include <atlbase.h>
#include <stdio.h>
#include <shlobj.h>
#include <string>
#pragma comment(lib, "userenv")