Skip to content

Instantly share code, notes, and snippets.

[
{
"key": "cmd+shift+l",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "console.dir(${TM_SELECTED_TEXT}$1, { depth: null })$0;"
}
}
]
@stevebauman
stevebauman / vite.config.js
Last active May 8, 2025 01:08
Vite Server Cors Allow Any Subdomain
import { defineConfig, loadEnv } from 'vite';
// ...
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd());
const { protocol, hostname } = new URL(env.VITE_URL);
const root = hostname.split('.').slice(-2).join('\\.');
sources:
scratch_logs:
type: "journald"
include_units: ["scratchworker.service", "scratchdb.service"]
init_logs:
type: "journald"
include_units: ["init.scope"]
@J-Swift
J-Swift / provision.sh
Created March 1, 2023 20:19
nix auto-updating system with flakes
#!/usr/bin/env bash
set -euo pipefail
readonly flake_name='u3macbook'
readonly real_script_dir=$( dirname $(readlink $HOME/.config/nixpkgs/flake.nix) )
header() {
local -r msg="${1:-}"
@emidoots
emidoots / ramblings.md
Last active December 25, 2024 04:39
Because cross-compiling binaries for Windows is easier than building natively

Because cross-compiling binaries for Windows is easier than building natively

I want Microsoft to do better, want Windows to be a decent development platform-and yet, I constantly see Microsoft playing the open source game: advertising how open-source and developer friendly they are - only to crush developers under the heel of the corporate behemoth's boot.

The people who work at Microsoft are amazing, kind, talented individuals. This is aimed at the company's leadership, who I feel has on many occassions crushed myself and other developers under. It's a plea for help.

The source of truth for the 'open source' C#, C++, Rust, and other Windows SDKs is proprietary

You probably haven't heard of it before, but if you've ever used win32 API bindings in C#, C++, Rust, or other languages, odds are they were generated from a repository called microsoft/win32metadata.

@sindresorhus
sindresorhus / esm-package.md
Last active July 6, 2025 04:40
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@danvy
danvy / WSL2-Net-Fix.ps1
Created September 5, 2020 21:04
Reset your WSL network connection trying to fix WSL2 media disconnected error
# Check these threads before proceeding:
# https://github.com/microsoft/WSL/discussions/5857
# https://github.com/microsoft/WSL/issues/5821
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
$CmdLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CmdLine
Exit
}
# Restart the Host Network Service
Restart-Service -Force -Name hns
@Prakhar0409
Prakhar0409 / epidemic.md
Last active May 31, 2025 09:54
This gist describes two basic epidemic-like algorithms (Anti-entropy and Rumor Mongering) which are highly popular and used for maintaining consistency across replicated databases

Epidemic Algorithms for Replicated Database Management

Why use?

Maintaining mutual consistency across different sites, on updates, insertion and deletions, when a database is replicated is non-trivial and a significant problem. Though, it sounds reasonable to maintain a list of all replication servers and send direct updates to all when an update occurs at a site, it can cause large network load on the link of the node that has the initial update. Also, in case of constantly adding and leaving nodes, maintaining a consistent list of a million or a few hundered thousand nodes at every site consistently itself is difficult. In the face of the above mentioned problems, the algorithms described in the paper can come in handy.

The described algorithms have been used in the clearinghouse servers of the Xerox Corporate Internet and have proven to be very useful.

Formal introduction to the Problem

@andymatuschak
andymatuschak / States-v3.md
Last active June 3, 2025 20:57
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@eatonphil
eatonphil / functions.c
Last active June 26, 2025 11:24
Introduction to "Fun" C (using GCC)
/**
* This are a collection of examples for C 201.
* These combine concepts you may or may not be
* familiar with and are especially useful for
* students new to C. There is a lot of really
* cool stuff you can do in C without any cool
* languages.
*
* This is file in particular is an introduction
* to fun function usage in C.