Skip to content

Instantly share code, notes, and snippets.

View michel-pi's full-sized avatar

Michel michel-pi

View GitHub Profile
@michel-pi
michel-pi / TimerService.cs
Created March 6, 2020 01:10
Windows timer resolution and high accuracy Sleep
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
namespace Testing
{
internal static class StopwatchExtensions
{
public static long GetElapsedNanoseconds(this Stopwatch watch)
@michel-pi
michel-pi / EnvironmentEx.cs
Created April 24, 2020 05:26
Retrieves all Environment Variables
using System;
using System.Collections.Generic;
using System.Threading;
using System.Runtime.InteropServices;
namespace System
{
public static class EnvironmentEx
{
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, SetLastError = true)]
@michel-pi
michel-pi / NTStatusHelper.cs
Created April 5, 2019 15:37
Provides an up2date NTSTATUS enum and helper methods to use them.
using System;
namespace Microsoft.Win32
{
/// <summary>
/// Provides static helper methods to work with NTSTATUS values.
/// </summary>
public static class NTStatusHelper
{
/// <summary>
@michel-pi
michel-pi / SystemError.cs
Created April 5, 2019 15:34
Contains "all" system error codes
// use System.ComponentModel.Win32Exception instead
using System;
namespace Microsoft.Win32
{
/// <summary>
/// Contains all system error codes.
/// </summary>
public enum SystemError : uint
@michel-pi
michel-pi / SecureStaticRandom.cs
Created April 1, 2019 07:21
A static and thread safe cryptographic Random Number Generator (RNG)
using System;
namespace System.Security.Cryptography
{
/// <summary>
/// Represents a static and thread safe cryptographic Random Number Generator (RNG) using the implementation provided by the cryptographic service provider (CSP).
/// </summary>
public static class SecureStaticRandom
{
private const long MAX_EXCLUSIVE_UINT = 1 + (long)uint.MaxValue;
@michel-pi
michel-pi / wmi-events.txt
Created January 2, 2021 15:46
Windows 10 v2004 WMI Event Class List
__Event
__ExtrinsicEvent
Win32_DeviceChangeEvent
Win32_SystemConfigurationChangeEvent
Win32_VolumeChangeEvent
MSFT_WMI_GenericNonCOMEvent
MSFT_NCProvEvent
MSFT_NCProvCancelQuery
MSFT_NCProvClientConnected
MSFT_NCProvNewQuery
@michel-pi
michel-pi / cloudflare-dns.cmd
Created January 11, 2021 23:16
set cloudflare dns server with console
@echo off
netsh interface ipv4 set dnsservers name="Ethernet" validate=no static 1.1.1.1 primary > nul
netsh interface ipv4 add dnsservers name="Ethernet" validate=no 1.0.0.1 index=2 > nul
netsh interface ipv6 set dnsservers name="Ethernet" validate=no static 2606:4700:4700::1111 primary > nul
netsh interface ipv6 add dnsservers name="Ethernet" validate=no 2606:4700:4700::1001 index=2 > nul
ipconfig /flushdns > nul
@michel-pi
michel-pi / open-recyclebin.cmd
Created January 11, 2021 23:17
opens the recycle bin in a new windows explorer window
@echo off
start shell:RecycleBinFolder
exit
https://marketplace.visualstudio.com/items?itemName=josefpihrt.Roslynator2019
https://marketplace.visualstudio.com/items?itemName=SteveCadwallader.CodeMaid
https://marketplace.visualstudio.com/items?itemName=TeamXavalon.XAMLStyler
https://marketplace.visualstudio.com/items?itemName=MichaelKissBG8.Supercharger
https://marketplace.visualstudio.com/items?itemName=MadsKristensen.FileIcons
https://marketplace.visualstudio.com/items?itemName=EWoodruff.VisualStudioSpellCheckerVS2017andLater
https://marketplace.visualstudio.com/items?itemName=NikolayBalakin.Outputenhancer
https://marketplace.visualstudio.com/items?itemName=ironcev.sharpen
@michel-pi
michel-pi / FriendCode.cs
Created June 13, 2021 16:50
Generates friend codes for csgo or turns them into steam id's
using System;
using System.Buffers.Binary;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
namespace Csgo
{
public static class FriendCode
{