Skip to content

Instantly share code, notes, and snippets.

View ddjerqq's full-sized avatar
🐙
말보다는 행동이지

10x developer ddjerqq

🐙
말보다는 행동이지
View GitHub Profile
var size = Random.Shared.Next(0, 1_000_000);
var numbers = Enumerable.Range(0, size).ToArray();
Random.Shared.Shuffle(numbers);
// we are allowed a total of 5 observations, we must use
// the average gap method to approximate the number of elements
var observationCount = 100;
var observations = numbers.Take(observationCount).ToArray();
var maxObserved = observations.Max();
@ddjerqq
ddjerqq / UnsafeSha256.cs
Created June 30, 2024 12:53
Implementation of sha256 in C#, with unsafe code blocks
using System.Diagnostics;
using System.Text;
unsafe
{
Sha256 sha256 = new Sha256();
var payload = "aaa";
byte[] data = Encoding.UTF8.GetBytes(payload);
@ddjerqq
ddjerqq / UserAgent.cs
Last active May 29, 2024 22:48
A C# random user agent provider, useful for testing web API's and how they handle different types of devices.
public class UserAgent
{
private static readonly string[] UserAgents =
[
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.1 (KHTML, like Gecko) Chrome/4.0.219.6 Safari/532.",
"Opera/9.80 (Windows NT 5.2; U; ru) Presto/2.5.22 Version/10.5",
"Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20090913 Firefox/3.5.",
"Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 2.0.50727",
"Mozilla/5.0 (Windows; U; Windows NT 5.2; de-de; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729",
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.1) Gecko/20090718 Firefox/3.5.1 (.NET CLR 3.0.04506.648",
@ddjerqq
ddjerqq / blog.md
Last active April 27, 2024 19:35
A blog written for Blazorise

How to create a ShareButton component with Blazorise!

Are you ready to sprinkle some Blazorise magic into your Blazor app?
Adding share buttons for social media platforms can give your users an easy
way to spread the word about your awesome content. It's easier than you think, thanks to Blazorise!

image


@ddjerqq
ddjerqq / dependency-injection.py
Created January 13, 2024 07:45
python dependency injection using dependency-injector package
import os
import sys
import logging
import sqlite3
from typing import Dict
from dependency_injector.wiring import Provide, inject
from dependency_injector import containers, providers
@ddjerqq
ddjerqq / Mediator.py
Created January 13, 2024 07:40
python very simple mediator usage
import asyncio
import time
from typing import TypeVar
from mediatr import Mediator, GenericQuery
T = TypeVar("T")
class BaseQuery(GenericQuery[T]):
@ddjerqq
ddjerqq / Rfc6238.cs
Last active November 13, 2023 17:15
TOTP: Time-Based One-Time Password Algorithm Implementation in C#
using System.Security.Cryptography;
namespace Rfc6238;
public enum HmacAlgo
{
Sha1,
Sha256,
Sha512,
}
@ddjerqq
ddjerqq / PrivateKey.cs
Created September 29, 2023 17:03
C# implementation and easy abstraction for RSA cryptographic encryption algorithm
using System.Security.Cryptography;
using Newtonsoft.Json;
namespace Crypto;
public struct PrivateKey
{
private byte[] D { get; init; }
private byte[] P { get; init; }
@ddjerqq
ddjerqq / Sha256.cs
Created August 17, 2023 22:49
ILGPU implementation of SHA256 on the GPU
#pragma warning disable CS0649
using ILGPU;
using ILGPU.Runtime;
namespace Hasher;
public unsafe struct Sha256
{
/**************************** VARIABLES *****************************/
@ddjerqq
ddjerqq / AsyncQueue.cs
Created August 7, 2023 19:57
A thread-safe asynchronous queue.
using System.Threading.Tasks.Dataflow;
namespace AsyncQueue;
/// <summary>
/// A thread-safe asynchronous queue.
/// </summary>
/// <example>
/// <code>
/// var queue = new AsyncQueue`int();