Skip to content

Instantly share code, notes, and snippets.

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

tenxdeveloper ddjerqq

🐙
말보다는 행동이지
View GitHub Profile
public static class ExpandoExt
{
/// <summary>
/// Add a property to a dynamic object at runtime.
/// </summary>
/// <example>
/// dynamic expando = new ExpandoObject();
/// expando.Name = "Brian";
/// expando.Country = "USA";
/// expando.AddProperty("Language", "English");
@ddjerqq
ddjerqq / ThemeToggle.razor
Created May 7, 2025 18:54
TailwindCSSThemeToggle.razor
<Button Size="icon" Variant="outline" onclick="window.toggleTheme()" class="relative transform-gpu transition-all duration-300 ease-in-out">
<Blazicon Svg="@Icons.Sun" class="absolute rotate-0 dark:rotate-90 opacity-100 dark:opacity-0"/>
<Blazicon Svg="@Icons.Moon" class="absolute dark:rotate-0 rotate-90 dark:opacity-100 opacity-0"/>
</Button>
@ddjerqq
ddjerqq / .env.example
Last active April 6, 2025 20:21
asp.net core JWT with RSA JWE payload encryption and ECDSA nistP256 for signature generation, all loaded from keys and env variables
JWT__ISSUER=me
JWT__AUDIENCE=you
JWT__EXPIRATION=01:00:00
JWT__ENCRYPTION_KEY_PASSWORD=private key password
JWT__ENCRYPTION_KEY_PATH=/path/to/jwt_encryption_key.pem
JWT__SIGNING_KEY_PATH=/path/to/jwt_signing_key.pem
@ddjerqq
ddjerqq / JwtGenerator.cs
Last active April 3, 2025 10:32
dotnet JWT generator using an RSA encrypted private key
public static class JwtGenerator
{
public const string TokenName = "authorization";
public static readonly string ClaimsIssuer = "JWT__ISSUER".FromEnvRequired();
public static readonly string ClaimsAudience = "JWT__AUDIENCE".FromEnvRequired();
private static readonly string Key = "JWT__KEY".FromEnvRequired();
private static readonly string KeyPath = "JWT__KEY_PATH".FromEnvRequired();
/// <summary>
@ddjerqq
ddjerqq / LikenessFilterableHasher.cs
Last active February 2, 2025 11:05
C# data protection class, that uses Blake3 to securely hash arbitrary UTF8 strings using a data specific key, to allow for querying for encrypted data using LIKEness filters. Primarily for EFCore. Will add this to Klean.EntityFrameworkCore.DataProtection soon
using System.Diagnostics;
using System.Security.Cryptography;
using System.Text;
using Blake3;
public static class LikenessFilterableHasher
{
/// <summary>
/// Chunks a UTF8 string into runes. Each rune has each character's bytes (up to four bytes per char)
/// </summary>
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