Skip to content

Instantly share code, notes, and snippets.

import type { Plugin } from 'vite'
import path from 'path'
const name = 'prevent-server-data-circular-imports'
const defaultOptions = { verbose: false }
// Detect if the module is in server-data
const serverDataFileRegexp = /(.*)?server-data\/src\//
// Extract the imported path
@akarpov89
akarpov89 / InterpolatedParsing.cs
Created October 1, 2021 14:58
Interpolated parsing technique
using System.Runtime.CompilerServices;
using static ParsingExtensions;
string input = "Name: Andrew; Age: 31";
string? name = null;
int age = 0;
if (input.TryParse($"Name: {Placeholder(ref name)}; Age: {Placeholder(ref age)}"))
{
@davidfowl
davidfowl / .NET6Migration.md
Last active April 11, 2025 11:12
.NET 6 ASP.NET Core Migration
@NickCraver
NickCraver / Microsoft.PowerShell_profile.ps1
Last active March 5, 2025 22:33
Craver's oh-my-posh profile
# This goes in your Microsoft.PowerShell_profile.ps1 (can find the path via $PROFILE in your prompt)
Import-Module -Name posh-git,oh-my-posh,Terminal-Icons
Set-PoshPrompt -Theme craver
@MarkPflug
MarkPflug / IgnoreWhitespaceStringComparer.cs
Last active November 19, 2021 08:15
IgnoreWhitespaceStringComparer
using System;
using System.Collections.Generic;
namespace Sylvan
{
public sealed class IgnoreWhitespaceStringComparer : IEqualityComparer<string>
{
public static readonly IEqualityComparer<string> Instance = new IgnoreWhitespaceStringComparer(0);
public static readonly IEqualityComparer<string> IgnoreCase = new IgnoreWhitespaceStringComparer(0x20);
@davidfowl
davidfowl / Example.cs
Last active June 6, 2023 08:10
An implementation of MessagePipe. Something like a channel but with buffer management so you can peek and advance the message that was read.
using System.Buffers;
using System.Net.WebSockets;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/ws", async (HttpContext context) =>
{
const int MaxMessageSize = 1024 * 1024;
Install-Module NtObjectManager
Import-Module NtObjectManager
$Servers = Get-RpcServer -Path C:\Windows\system32\efssvc.dll `
-DbgHelpPath 'C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\dbghelp.dll'
$EfsInterace = $Servers | Where-Object { $_.InterfaceId -eq 'df1941c5-fe89-4e79-bf10-463657acf44d' }
$client = Get-RpcClient -Server $EfsInterace
$client.Connect()
@sonnemaf
sonnemaf / RecordStructBenchmark.cs
Created July 27, 2021 15:00
Benchmark showing that a record struct with fields can be faster than with properties. Around 9% faster on my PC. If you change decimal to int they are equally fast.
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
namespace RecordStructBM {
class Program {
static void Main(string[] args) {
BenchmarkRunner.Run<BM>();
}
}
// Estimating CPU frequency...
// CPU frequency: 4.52 GHz
// sum1: value = 15182118497126522709, 0.31 secs, 5.14 cycles/elem
// sum2: value = 15182118497126522709, 0.17 secs, 2.93 cycles/elem
#define RW(x) asm("" : "+r"(x))
typedef struct Node {
u64 value;
struct Node *next;

Cheat sheet: JavaScript Array methods

Deriving a new Array from an existing Array:

['■','●','▲'].slice(1, 3)           ['●','▲']
['■','●','■'].filter(x => x==='■')  ['■','■']
    ['▲','●'].map(x => x+x)         ['▲▲','●●']
    ['▲','●'].flatMap(x => [x,x])   ['▲','▲','●','●']