Skip to content

Instantly share code, notes, and snippets.

@nathancorvussolis
nathancorvussolis / wix-v5-bootstrap-download-vcredist-sample.wxs
Last active January 15, 2025 06:52
WiX v4/v5 - Visual C++ 2015-2022 Redistributable - 14.40.33810
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:bal="http://wixtoolset.org/schemas/v4/wxs/bal"
xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
<Bundle
Name="Example Product"
Version="1.2.3.4"
Manufacturer="John Doe"
Copyright="© 2023 John Doe"
AboutUrl="https://example.net/"
@ygoe
ygoe / ps-csharp.cmd
Created January 29, 2022 23:20
Write your Windows batch files in C# (using PowerShell)
<# :
@echo off & setlocal & set __args=%* & %SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Command Invoke-Expression ('. { ' + (Get-Content -LiteralPath ""%~f0"" -Raw) + ' }' + $env:__args) & exit /b %ERRORLEVEL%
#> Add-Type @'
// ========== BEGIN C# CODE ==========
using System;
public class App
{
public static void Run(string[] args)
{
@aannenko
aannenko / AwaiterTaskSource.cs
Last active November 11, 2023 19:45
One Task, many awaiters - starts a task, issues awaiter-tasks for it, tracks the task until it's finished or all awaiter-tasks are cancelled.
#nullable enable
using System;
using System.Threading;
using System.Threading.Tasks;
public sealed class AwaiterTaskSource<TResult>
{
private readonly CancellationTokenSource _cancellationTokenSource;
private int _awaitersCount = 0;
@ygoe
ygoe / ProcessHelper.cs
Created December 17, 2020 13:46
ProcessHelper class: Provides methods for process execution and handling in C#. Because it's hard.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using DotforwardControl.Shared.Extensions;
namespace DotforwardControl.Shared.Util
{
@ygoe
ygoe / ManagedUnixCrypt.cs
Created August 30, 2020 17:48
A managed implementation of the Unix C library crypt function. Supports MD5, SHA-256 and SHA-512.
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace YourApp.Util
{
/// <summary>
/// A managed implementation of the Unix C library crypt function. It supports the MD5, SHA-256
/// and SHA-512 algorithms.
@djfdyuruiry
djfdyuruiry / README.md
Last active October 8, 2024 04:54
WSL 2 - Enabling systemd

Enable systemd in WSL 2

NOTE: If you have Windows 11 there is now an official way to do this in WSL 2, use it if possible - see MS post here (WINDOWS 11 ONLY)

This guide will enable systemd to run as normal under WSL 2. This will enable services like microk8s, docker and many more to just work during a WSL session. Note: this was tested on Windows 10 Build 2004, running Ubuntu 20.04 LTS in WSL 2.

  • To enable systemd under WSL we require a tool called systemd-genie

  • Copy the contents of install-sg.sh to a new file /tmp/install-sg.sh:

@aannenko
aannenko / CryptSharp.cs
Last active August 30, 2023 17:18
CryptSharp - crypt(3) via C# and .NET Core (min .NET Core version = 2.1; min .NET Standard = 2.1)
using System;
namespace Crypt
{
public static class CryptSharp
{
private const string m_encryptionSaltCharacters =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
private const int m_desIterations = 16;
@47star
47star / Set-VMIPAddress.ps1
Created April 5, 2019 15:23
Assign static IP address for Hyper-V Guest.
param( [String]$VMName="",
[String]$Address="",
[String]$Gateway="",
[String]$SubnetMask="",
[String]$DNS1="",
[String]$DNS2="")
$Msvm_VirtualSystemManagementService = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_VirtualSystemManagementService
$Msvm_ComputerSystem = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_ComputerSystem -Filter "ElementName='$VMName'"
$Msvm_VirtualSystemSettingData = ($Msvm_ComputerSystem.GetRelated("Msvm_VirtualSystemSettingData", "Msvm_SettingsDefineState", $null, $null, "SettingData", "ManagedElement", $false, $null) | % {$_})
$Msvm_SyntheticEthernetPortSettingData = $Msvm_VirtualSystemSettingData.GetRelated("Msvm_SyntheticEthernetPortSettingData")
@degski
degski / invertible_hash_functions.hpp
Last active July 27, 2024 16:52
invertible hash functions
// MIT License
//
// Copyright (c) 2018 degski
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@ygoe
ygoe / WindowsRegistry.cs
Created July 20, 2017 08:56
A class that provides Windows registry access for .NET Framework (define NETFULL) and .NET Standard 1.6 (define NETSTANDARD) projects through P/Invoke.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Win32;
namespace MyNamespace
{
internal class WindowsRegistry