Skip to content

Instantly share code, notes, and snippets.

@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 October 12, 2023 12:40
IBM DB .NET Core Provider

IBM Db2 data provider for .NET Core / .NET 5+

/edit I made this page in Feb 2020 because there was no documentation publicly available, and I wanted to share what little information I could find. That's probably how you found this page. I'm not associated with IBM.

There are three packages for .NET Core 3.1

  • [IBM.Data.DB2.Core] for Windows 64-bit
  • [IBM.Data.DB2.Core-lnx] for Linux AMD64
  • [IBM.Data.DB2.Core-osx] for Mac
@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,
@sliekens
sliekens / compare-files.ps1
Last active July 12, 2018 08:39
Comparing git-ls-files to actual filenames
Compare-Object `
-ReferenceObject (git ls-files | Resolve-Path -Relative | Sort-Object) `
-DifferenceObject (Get-ChildItem -Recurse -File | Resolve-Path -Relative | Sort-Object) `
-CaseSensitive `
-SyncWindow 0