Skip to content

Instantly share code, notes, and snippets.

Michel michel-pi

Block or report user

Report or block michel-pi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@michel-pi
michel-pi / TimerService.cs
Created Mar 6, 2020
Windows timer resolution and high accuracy Sleep
View TimerService.cs
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)
View discord-widget-data.js
function DiscordWidgetData() {
this.load = async function (guildId) {
return new Promise(function (resolve, reject) {
fetch("https://discordapp.com/api/v6/guilds/" + guildId + "/widget.json", {
method: "GET",
mode: "cors",
cache: "reload",
redirect: "follow"
}).then(response => {
if (!response.ok) {
@michel-pi
michel-pi / HashProvider.cs
Created May 29, 2019
Provides static methods to use hash algorithms in a generic way.
View HashProvider.cs
using System;
using System.Text;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
namespace System.Security.Cryptography.Provider
{
/// <summary>
/// Provides static methods to use hash algorithms in a generic way.
/// </summary>
@michel-pi
michel-pi / WindowExtensions.cs
Last active May 29, 2019
Provides extension methods for WPF windows such as Invoke, enabling drag move, control sliders through the mouse wheel and enumerating controls.
View WindowExtensions.cs
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Media3D;
namespace System.Windows.Extensions
{
@michel-pi
michel-pi / NTStatusHelper.cs
Created Apr 5, 2019
Provides an up2date NTSTATUS enum and helper methods to use them.
View NTStatusHelper.cs
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 Apr 5, 2019
Contains "all" system error codes
View SystemError.cs
// 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 Apr 1, 2019
A static and thread safe cryptographic Random Number Generator (RNG)
View SecureStaticRandom.cs
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 / StaticRandom.cs
Created Apr 1, 2019
A static and thread safe pseudo-random number generator
View StaticRandom.cs
using System;
using System.Threading;
namespace System
{
/// <summary>
/// Represents a static and thread safe pseudo-random number generator, which is a device that produces a sequence of numbers that meet certain statistical requirements for randomness.
/// </summary>
public static class StaticRandom
{
@michel-pi
michel-pi / AsyncKeyState.cs
Last active Dec 23, 2018
GetAsyncKeyState wrapper
View AsyncKeyState.cs
using System;
using System.Runtime.InteropServices;
namespace System.Input
{
public static class AsyncKeyState
{
[DllImport("user32.dll")]
private static extern short GetAsyncKeyState(int key);
@michel-pi
michel-pi / IntPtrExtensions.cs
Last active Dec 23, 2018
Extension methods to validate IntPtr's and count with them
View IntPtrExtensions.cs
using System;
namespace System
{
public static class IntPtrExtensions
{
private static readonly bool _x86 = IntPtr.Size == 4;
public static ulong GetValue(this IntPtr ptr)
{
You can’t perform that action at this time.