Skip to content

Instantly share code, notes, and snippets.

View xoofx's full-sized avatar
🏠
Working from home

Alexandre Mutel xoofx

🏠
Working from home
View GitHub Profile
@xoofx
xoofx / BenchSourceGenerator.cs
Created December 29, 2020 12:52
Small benchmark for source generators between Scriban and Roslyn
// Requires the following packages:
// <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" />
// <PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
// <PackageReference Include="Scriban" Version="3.2.2" />
//
// BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19041.685 (2004/?/20H1)
// AMD Ryzen 9 3900X, 1 CPU, 24 logical and 12 physical cores
// .NET Core SDK=5.0.101
// [Host] : .NET Core 5.0.1 (CoreCLR 5.0.120.57516, CoreFX 5.0.120.57516), X64 RyuJIT
// DefaultJob : .NET Core 5.0.1 (CoreCLR 5.0.120.57516, CoreFX 5.0.120.57516), X64 RyuJIT
@xoofx
xoofx / lemonde-dark.css
Created December 28, 2020 18:06
Dark mode for LeMonde.fr with Stylish
/*
Dark Mode for the Le Monde web site at https://www.lemonde.fr/
Using Stylish Chrome Extension: https://chrome.google.com/webstore/detail/stylish-custom-themes-for/fjnbnpbmkenffdnngjfgmeleoegfcffe?hl=en
With "URLs starting with:" = https://www.lemonde.fr/
*/
@media(prefers-color-scheme:dark)
{
#Header .Header, .Nav, .Nav__sub-item, body, .main, .zone, section.article__heading, .article__paragraph, .article, .article--longform .article__title, .article--longform .article__heading, .article--featured .article__wrapper, .article__title, .article__sub-title, .article__desc, .insert, div.fw_most_read_recommendations, .fw_most_read_recommendations-article, a .fw_most_read_recommendations-article {
background-color: #141414;
@xoofx
xoofx / StructLayoutBug.cs
Created November 11, 2020 19:37
StructLayoutBug
using System;
using System.Linq;
using System.Runtime.InteropServices;
// Requires the NuGet package https://www.nuget.org/packages/ObjectLayoutInspector/
namespace StructLayoutApp
{
[StructLayout(LayoutKind.Explicit)]
struct ExplicitLayoutStruct {
[FieldOffset(0)] public byte B00;
@xoofx
xoofx / DirectCallProgram.cs
Created September 25, 2020 17:32
Use calli to delay call to Update methods on a bunch of objects
using System;
using System.Diagnostics;
using System.Reflection;
using InlineIL;
namespace DirectCallApp
{
// With the following csproj
// <Project Sdk="Microsoft.NET.Sdk">
//
@xoofx
xoofx / migrating-issue-project-tracking-system.md
Last active September 18, 2020 07:45
What it really takes to migrate from one issue/project tracking system to another?

Migrating from an issue/project tracking system to another

  • An issue/project-tracking system is a living source of information for a team managing a project.
  • It contains various history of discussions, decisions, links, comments, mentions, tags and labels...etc.
  • When transitioning from one issue system to another, it is critical to maintain a high fidelity translation of the previous issues into the new system.
  • Often, decisions to migrate are taken at a high level in your company for various reasons, but the execution of the migration could be not prepared and supported at all by your company. In that case:
    • Try to push this preparation to happen company wide.
    • Beware that your team might have to do it on its own because nobody is available to do this for you or, worse, to do it correctly.

What it really takes to migrate?

@xoofx
xoofx / TuplesFeedbackProgram.cs
Last active February 17, 2020 17:52
Feedback on dynamic Tuples experiment https://github.com/YohDeadfall/Yoh.Tuples
// Feedback on https://github.com/YohDeadfall/Yoh.Tuples
/*
| Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
|---------------- |----------:|---------:|---------:|-------:|------:|------:|----------:|
| TestSimpleTuple | 50.02 ns | 0.423 ns | 0.396 ns | 0.0229 | - | - | 192 B |
| TestYohTuple | 739.97 ns | 1.783 ns | 1.580 ns | 0.1822 | - | - | 1528 B |
*/
using System;
using System.Runtime.CompilerServices;
@xoofx
xoofx / InvalidLdfldaIL.cs
Created December 11, 2019 17:36
Example of the ldflda opcode crashing on Mono (5.21 and 6.4.0)
// Create a .NET Core project, target also net472
// Requires to install NuGet package InlineIL.Fody https://github.com/ltrzesniewski/InlineIL.Fody in your project
// Run this program
using System;
using InlineIL;
namespace PlayIL
{
class Program
{
@xoofx
xoofx / LinuxUtil.cs
Created November 11, 2019 19:56
Run the same Linux command transparently from Windows (via WSL) and Linux
// Copyright 2019 - Alexandre MUTEL - License MIT
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
// Example of running a Linux command from .NET that can run transparently on Windows (via WSL) or Linux
// Assuming you are running on the same distribution, you can integrate this in your tests for example.
namespace YourNameSpace.Tests
@xoofx
xoofx / BenchGCHandleReused.cs
Created September 21, 2019 16:30
Bench of GCHandle reused
// The following benchmark shows a barely known capability of GCHandle to be reused via their .Target
// as it is avoiding to reallocate an expensive entry into the GC table handle in the CLR runtime
/*
BenchmarkDotNet=v0.10.12, OS=Windows 10.0.18362
AMD Ryzen 9 3900X 12-Core Processor, 1 CPU, 24 logical cores and 12 physical cores
.NET Core SDK=3.0.100-rc1-014190
[Host] : .NET Core 2.1.13 (Framework 4.6.28008.01), 64bit RyuJIT
DefaultJob : .NET Core 2.1.13 (Framework 4.6.28008.01), 64bit RyuJIT
@xoofx
xoofx / BenchXXH3Fast.cs
Last active September 14, 2019 07:51
Experiment with XXH3Fast and XXH3FastSSE
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Text;
using BenchmarkDotNet.Attributes;
using StarkPlatform.NativeCompiler.Utils;
namespace StarkPlatform.NativeCompiler.Benchmarks
{
[DisassemblyDiagnoser]
public class BenchXXH3