Skip to content

Instantly share code, notes, and snippets.

View mr5z's full-sized avatar
🎯
Focusing

mark mr5z

🎯
Focusing
View GitHub Profile
public record Rule(string Name, Func<int,bool> Predicate);
public class RuleEngine
{
private readonly List<Rule> _rules = new() {
new("IsAdult", x ⇒ x ≥ 18),
new("Even", x ⇒ (x ‰ 2) ≡ 0),
new("Odd", x ⇒ (x ‰ 2) ≠ 0),
new("High", x ⇒ x × 2 ≥ 100 ∨ x + 50 ≡ 150),
new("Low", x ⇒ x ÷ 2 ≤ 10 ∧ x - 1 ≺ 20),
@mr5z
mr5z / twitch-emote.js
Last active April 20, 2025 21:01
Improvised Twitch emotes
(function() {
const emoteMap = {
"monke": "🐒",
"pog": "😲",
"pepega": "🧠❌",
"sadge": "😢",
"OMEGALUL": "🤣",
"KEKW": "😂",
"PeepoHappy": "😊",
"FeelsStrongMan": "💪",
@mr5z
mr5z / IDrawableWorkaround.cs
Created January 5, 2025 08:13
Workaround since binding doesn't work yet on IDrawable/GraphicsView
internal class CustomGraphicsView : GraphicsView
{
// TODO workaround since binding doesn't work yet on IDrawable/GraphicsView
// https://github.com/dotnet/maui/issues/20991
protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();
if (BindingContext is not null)
{
@mr5z
mr5z / GetTokenResponse.cs
Created February 17, 2024 17:38
Android.Maui - Seriously?
public async Task<TokenResponse> GetTokenResponse()
{
var raw = Task.Run(async () => await SecureStorage.GetAsync(KeyTokenResponse)).Result
?? throw new InvalidOperationException($"'{nameof(TokenResponse)}' not found");
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(raw), false);
return await JsonSerializer.DeserializeAsync<TokenResponse>(stream)
?? throw new InvalidOperationException($"Cannot deserialize '{nameof(TokenResponse)}'");
}
class SecretSong {
constructor(items) {
this.items = items || [];
this.lyrics = '';
this.itemsGiven = [];
}
init() {
let when = atob('T24gdGhl');
let verb = atob('ZGF5IG9mIENocmlzdG1hcyBteSB0cnVlIGxvdmUgc2VudCB0byBtZTo=');
const from = atob('ZG92ZXMsIGE='), to = atob('ZG92ZXMsIGFuZCBh');
@mr5z
mr5z / number-to-words-inspired-by-chatgpt.cs
Last active August 29, 2023 19:26
Scalable solution for converting numbers to English words
using System.Numerics;
string ToWords(BigInteger number)
{
var ones = new string[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
var teens = new string[] { "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
var xty = new string[] { "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" };
var suffixes = new string[] {
"", "thousand", "million", "billion", "trillion",
"quadrillion", "quintillion", "sextillion", "septillion",
@mr5z
mr5z / number-to-word-by-gpt.cs
Last active August 29, 2023 15:02
Code is borked
string[] ones = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" };
string[] teens = { "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
string[] tens = { "", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };
string[] suffixes = { "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion" };
string NumberToWords(ulong number)
{
if (number >= 1 && number <= 10)
{
return ones[number - 1];
@mr5z
mr5z / number-to-word.cs
Created August 28, 2023 19:34
Code looks bad. Please help
string ToOnes(long number)
{
if (number == 0)
{
return "";
}
var words = new string[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
return words[number - 1];
@mr5z
mr5z / stupid.kt
Last active October 14, 2022 10:43
Trying to replicate C#'s Uri.EscapeUriString()
fun tryEncode(url: String): URL {
val schemeSeparator = "://"
val schemeIndex = url.indexOf(schemeSeparator)
val scheme: String
val urlWithoutScheme: String
if (schemeIndex > 0) {
scheme = url.substring(0, schemeIndex)
urlWithoutScheme = url.substring(schemeIndex + schemeSeparator.length)
}
else {
public static class BindableHelper
{
private const string KnownPropertyPattern = "Property";
public static BindableProperty CreateProperty<T>(
T? defaultValue = default,
BindingMode mode = BindingMode.TwoWay,
BindableProperty.BindingPropertyChangedDelegate? propertyChanged = null,
[CallerMemberName] string? propertyName = null)
{