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 / 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;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@xoofx
xoofx / BuildtimeOptimizedRoslynSourceGenerator.cs
Last active July 5, 2025 03:53
Roslyn Source Generator optimized for build time only usage
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using Microsoft.CodeAnalysis.Text;
namespace SourceGenLib
@xoofx
xoofx / BatchFinder.cs
Last active December 6, 2024 16:23
Optimized AVX2 version of finding the index of an integer from an array
// Discussion about https://mastodon.social/@denisio@dotnet.social/110644302160625267
// Optimized version using AVX. From 4x to 10x faster than a simple version.
// - nint for indexing
// - Unsafe.Add
// - Unrolling of 4 Vector256 + Or of the results to have only 1 branch per loop
// - Finding the local index within the Vector256 without a loop using AVX movemask
// Similar code can be done for Vector128
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@xoofx
xoofx / BatchSimdDot.cs
Created September 2, 2024 06:36
BatchSimdDot Example
// Comment about https://mastodon.social/@brandewinder@hachyderm.io/113064780292323247
// https://brandewinder.com/2024/09/01/should-i-use-simd-vectors/
using System.Numerics;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
public class VectorProcessor
{
public static float Take2(float[] left, float[] right)
{
@xoofx
xoofx / BenchWindowsTerminal.cs
Last active July 31, 2024 08:14
Bench Windows Terminal with a wall of 24-bits RGB ANSI scrolling chars
// Bench Windows Terminal with a wall of 24-bits RGB ANSI scrolling chars
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
var width = Console.WindowWidth;
var height = Console.WindowHeight;
var total = width * height;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@xoofx
xoofx / UUIDv7Fast.cs
Created June 16, 2024 05:11
UUIDv7Fast.cs
// From a discussion on mastodon https://mastodon.social/@antonz@c.im/112620103070756332
// This version:
// * simplifies the setup (an inline array is already a Span)
// * uses BinaryPrimitives.ReverseEndianness to batch writing the long to the buffer
// * uses SkipLocalsInit on the ctor to avoid some zero init
// Should be ~ 15% faster than the revised version with Span
// Anyway most of the time is spent in DateTimeOffset.UtcNow and RandomNumberGenerator.Fill
using System.Buffers.Binary;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".txt" #>
<#
var vectors = new [] { "Vector64", "Vector128", "Vector256", "Vector512", "Vector", "Vector2", "Vector3", "Vector4" };
var templates = new string[0];
string genT;
@xoofx
xoofx / ResizeWithSkia.cs
Created October 20, 2016 14:54
Resize an image and draw some overlay text with SkiaSharp
// You need to configure your C# project with x86 or x64 platform (Tools\Configuration Manager\Create new Platform on the project)
// otherwise the native libSkiaSharp.dll will not get copied
using System;
using System.IO;
using SkiaSharp;
namespace TestSkia
{
class Program
{