Skip to content

Instantly share code, notes, and snippets.

View smourier's full-sized avatar

Simon Mourier smourier

View GitHub Profile
@smourier
smourier / wicbitmaptests.cpp
Created December 22, 2023 06:48
Some WIC Bitmap tests
#include <windows.h>
#include <atlbase.h>
#include <stdio.h>
#include <wincodec.h>
#define HRASSERT(x) ATLASSERT(SUCCEEDED(x))
HRESULT ConvertBitmapTo256(PCWSTR input, PCWSTR output, REFGUID outputFormat)
{
HRESULT hr = S_OK;
@smourier
smourier / App.xaml.cs
Last active April 18, 2024 17:46
Create a WinUI3 Xaml window in another thread
using Microsoft.UI.Xaml;
namespace WinUIAppFx
{
public partial class App : Application
{
private Window m_window;
public App()
{
@smourier
smourier / UIA_NoFocusSetNotepadText.cs
Created August 26, 2023 09:42
Set notepad's text using UI automation w/o setting the focus on it first
static void Main()
{
// needs using UIAutomationClient;
// requires a reference to windows\system32\UIAutomationClient.dll
// and set Embed Interop Types to false for project reference
var root = new CUIAutomation8();
// we want to *keep* the focus
root.AutoSetFocus = 0; // false
@smourier
smourier / aniexport.cs
Created August 12, 2023 13:22
save .ANI (doesn't work, not sure why)
public static void SaveAsANI(Image inputImage, string outputFilePath)
{
ArgumentNullException.ThrowIfNull(inputImage);
ArgumentNullException.ThrowIfNull(outputFilePath);
using var stream = new FileStream(outputFilePath, FileMode.Create);
SaveAsANI(inputImage, stream);
}
public static void SaveAsANI(Image inputImage, Stream outputStream)
{
@smourier
smourier / SystemFirmwareTables.cs
Created July 17, 2023 13:02
Dump system firmware tables.
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
namespace ConsoleApp1
{
internal class Program
{
static void Main()
@smourier
smourier / DeleteThumbnail.cpp
Last active July 17, 2023 08:19
Delete a thumbnail (uses undocumented interface, use at your own risk)
#include <windows.h>
#include <stdio.h>
#include <atlbase.h>
#include <atlcom.h>
#include <thumbcache.h>
DECLARE_INTERFACE_IID_(IThumbnailCachePrivate, IUnknown, "3413b9cd-0db3-4e97-8bf4-68fb100d1815")
{
public:
virtual HRESULT STDMETHODCALLTYPE Method0();
@smourier
smourier / ag-grid-number-editor.js
Created July 1, 2023 07:24
An AG-Grid numeric editor that supports comma or dot as decimal separator.
// backspace starts the editor on Windows
const KEY_BACKSPACE = 'Backspace';
// a numeric editor that supports comma or dot as decimal separator
class numericEditor {
init(params) {
// get separator, only used for initial input
this.decimalSeparator = params.decimalSeparator;
// create the cell
@smourier
smourier / buildx64.bat
Created June 25, 2023 21:57
build sqlcipher for Windows x64 with OpenSSL
@build sqlcipher
@ 1. clone sqlcipher somewhere (in a sqlcipher directory).
@ 2. install a proper tclsh.exe and put it in the path https://www.activestate.com/products/tcl/
@ 3. install open SSL binaries & static libs https://slproweb.com/products/Win32OpenSSL.html
@ 4. create a "build" directory at same level
@ 5. create a "x64" directory under "build"
@ 6. copy this file in build\x64
@ 7. open "x64 Native Tools Command Prompt for VS 20XX"
@ 8. cd build\x64
@ 9. run buildx64.bat (this file copied in build\x64)
@smourier
smourier / Random.ts
Created May 18, 2023 13:17
A TypeScript port of .NET's System.Random
// by design, this returns the same values as .NET's System.Random
export default class Random {
private static readonly INT_MAX_VALUE: number = 0x7fffffff;
private static readonly INT_MIN_VALUE: number = 0x80000000;
private static readonly MSEED = 161803398;
private inext = 0;
private inextp = 21;
private seedArray = new Array(56);
@smourier
smourier / AStar.ts
Created May 15, 2023 13:54
A* implementation in TypeScript
export interface IHasNeighbours<T> {
getNeighbours(): Iterable<T>;
}
export class AStar {
static findPath<T extends IHasNeighbours<T>>(start: T, end: T, distanceFunc: (a: T, b: T) => number, estimateFunc?: (a: T) => number): Array<T> {
estimateFunc ??= (a: T) => distanceFunc(a, end);
const closed = new Set<T>();
const queue = new PriorityQueue<NodeWithNumber<Path<T>>>(NodeWithNumber.comparator);
queue.push(new NodeWithNumber(new Path<T>(start, undefined, 0), 0));