Skip to content

Instantly share code, notes, and snippets.

@huoshan12345
huoshan12345 / NullableAttributes.cs
Last active June 21, 2022 01:07
NullableAttributes
// https://gist.githubusercontent.com/huoshan12345/799a15cd0fa1e462ee16c68aaf361202/raw/7cadb46f9795d2a8f8bcd8091d0ccfa1fa9267f8/NullableAttributes.cs
#pragma warning disable MA0048 // File name must match type name
// ReSharper disable once CheckNamespace
#define INTERNAL_NULLABLE_ATTRIBUTES
#if NETSTANDARD2_0 || NETCOREAPP2_0 || NETCOREAPP2_1 || NETCOREAPP2_2 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 || NET472 || NET48
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace System.Diagnostics.CodeAnalysis
@huoshan12345
huoshan12345 / InterfaceBaseInvocationExtension.cs
Last active June 10, 2022 03:05
Interface Base Invocation
public static class InterfaceBaseInvocationExtension
{
private readonly record struct InterfaceMethodInfo(Type InstanceType, Type InterfaceType, MethodInfo Method);
private static readonly ConcurrentDictionary<InterfaceMethodInfo, Delegate> _delegates = new();
private readonly struct Unit { }
public static void Base<TInterface>(this TInterface instance, Expression<Action<TInterface>> selector)
{
@huoshan12345
huoshan12345 / encrypt.cs
Last active April 10, 2024 23:15
Instagram enc_password generator in C#
// Packages need to be installed:
// Sodium.Core
// System.Security.Cryptography.Algorithms
// The values of publicKey,keyId,version are from shared_data.
// You need to call https://www.instagram.com/data/shared_data/ to get shared_data first
public static string GenerateEncPassword(string password, string publicKey, string keyId, string version)
{
var time = DateTime.UtcNow.ToTimestamp(); // Unix timestamp
var keyBytes = publicKey.HexToBytes(); // Convert a hex string to a byte array