Skip to content

Instantly share code, notes, and snippets.

View sliekens's full-sized avatar

Steven sliekens

View GitHub Profile
@sliekens
sliekens / AspNetDefaults.csproj
Last active July 12, 2024 12:07
Aspire split defaults for web and workers
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireSharedProject>true</IsAspireSharedProject>
</PropertyGroup>
<ItemGroup>
@sliekens
sliekens / reply.md
Last active October 10, 2022 09:32
Reference data as code and EF

This is a reply to Reference data as code: https://enterprisecraftsmanship.com/posts/reference-data-as-code

I recommend reading it first, because it's good and because otherwise this won't make sense to you.

TLDR; I strongly recommend replacing static readonly fields with creation methods or equivalent getters.

public class Industry : Entity
{
- public static readonly IndustryCars = new Industry(1, "Cars");
@sliekens
sliekens / rant.md
Created May 11, 2022 21:41
How to nuke Git LFS files from your repository with filter-branch

You probably found this page because LFS storage quotas suck absolute balls and GitHub's response to the question to "how can I delete old unneeded files from your servers?" is "Fuck off and get fucked, loser." (Slightly paraphrased)

I refuse to delete my entire repository just to clear up LFS storage. Instead I removed all LFS files from my Git history and uninstalled LFS.

Command to list all commits with LFS files (basically a dry run):

git checkout main
git filter-branch --prune-empty --index-filter 'git lfs ls-files $GIT_COMMIT' 
@sliekens
sliekens / encapsulated-requests.md
Last active April 17, 2022 07:55
Encapsulate your requests

Encapsulate your requests

I've written a lot of code that accesses other web APIs so here are some of my thoughts about how to do it the right way in C#.

HttpClient

Let's take a closer look at the .NET HttpClient interface. Are you surprised? This design looks like they took too much of a good thing —convenience— and turned it into a bad thing: the burden of choice.

@sliekens
sliekens / ibm-data-db2.md
Last active November 12, 2024 18:51
IBM DB .NET Core Provider
@sliekens
sliekens / DiscriminatedJsonConverter.cs
Last active December 15, 2022 19:24
Configurable JsonConverter for deserializing discriminated JSON
using System;
using System.Diagnostics;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Infrastructure
{
public sealed class DiscriminatedJsonConverter : JsonConverter
{
@sliekens
sliekens / DesignedForInheritanceTest.cs
Last active May 14, 2019 23:04
Design for inheritance
using System;
using System.Linq;
using System.Reflection;
using Xunit;
namespace YourLibName.Tests.PatternsAndPractices
{
public class DesignedForInheritanceTest
{
public DesignedForInheritanceTest()
# Check the working directory for modified files
# Exit with an error if there are any
$modified = git ls-files --modified
if ($modified -ne $null) {
Write-Error "Working directory contains modified files: $modified"
exit 1
}
@sliekens
sliekens / rollup-plugin-vue-unofficial.ts
Created December 30, 2018 19:31
rollup-plugin-vue-unofficial
import { Plugin, PluginContext } from 'rollup';
import { createFilter } from 'rollup-pluginutils';
import {
parse,
compileTemplate,
TemplateCompileResult
} from '@vue/component-compiler-utils';
import { VueTemplateCompiler } from '@vue/component-compiler-utils/dist/types';
import {
ObjectExpression,
private static (BigInteger, BigInteger) RecoverPrimeFactors(BigInteger n, BigInteger e, BigInteger d)
{
// Inspired by https://www.di-mgt.com.au/rsa_factorize_n.html
var k = BigInteger.Subtract(BigInteger.Multiply(d, e), BigInteger.One);
var primes = new List<int>
{
2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
127, 131, 137, 139, 149, 151, 157, 163, 167, 173,