Skip to content

Instantly share code, notes, and snippets.

@dbrookman
dbrookman / build-mpv_silicon.sh
Last active April 5, 2025 10:57
How to build mpv & mpv.app on an Apple silicon Mac
#!/usr/bin/env bash
# Builds mpv & mpv.app on Apple silicon Macs.
# Run this script from the root directory of the mpv repo.
# if anything fails, gtfo
set -ex
meson setup build
meson compile -C build
@JustinGrote
JustinGrote / MandatoryProperties.ps1
Last active February 2, 2024 06:41
A Powershell Class with Mandatory Properties by Default
using namespace System.Collections
using namespace System.Management.Automation
using namespace System.ComponentModel.DataAnnotations
using namespace System.Runtime.Serialization
class MandatoryProperties {
MandatoryProperties([IDictionary]$properties) {
$this.GetType().GetProperties([System.Reflection.BindingFlags]'Instance,Public') | ForEach-Object {
$propertyName = $PSItem.Name
[bool]$isOptional = $PSItem.GetCustomAttributes([OptionalFieldAttribute], $true).count -gt 0
if (
@Ciantic
Ciantic / offsetRelativeTo.js
Created October 22, 2021 11:15
Get offset relative to selector or window
/**
* Get offset relative to selector (or window)
*
* @param {HTMLElement} el
* @param {string|undefined} selector if not give, assumes root most (window)
*/
function offsetRelativeTo(el, selector) {
let offsetTop = el.offsetTop;
let offsetLeft = el.offsetLeft;
let offsetParent = el.offsetParent;
@calicoday
calicoday / playground.js
Last active November 12, 2021 19:33
Refactored tree-sitter playground.js
// Dev switch for loading prev state or force canned eg.
let activateSaveState = true;
let showParseCount = true;
// Prelim sample input, drawn from the cli/src/tests/query_test.rs (as-is, excess space).
const eg = {
lang: 'javascript',
code: `
class Person {
// the constructor
@bitonic
bitonic / vectorized-atan2f.cpp
Last active August 9, 2024 12:54
Vectorized & branchless atan2f
// Copyright (c) 2021 Francesco Mazzoli <[email protected]>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
class DirectedGraph<T> {
readonly edges: Map<T, Set<T>> = new Map();
addAll(from: T, ...to: T[]) {
let dependencies = this.edges.get(from);
if (dependencies == null) {
dependencies = new Set();
this.edges.set(from, dependencies);
}
Sets.addAll(dependencies, to);
@mmozeiko
mmozeiko / shader.hlsl
Last active November 7, 2024 20:23
compute shader for rendering monospaced glyphs in grid
//
struct TerminalCell
{
// cell index into GlyphTexture, should be two 16-bit (x,y) values packed: "x | (y << 16)"
uint GlyphIndex;
// 0xAABBGGRR encoded colors, nonzero alpha for Foreground indicates to render colored-glyph
// which means use RGB values from GlyphTexture directly as output, not as ClearType blending weights
uint Foreground;
@Egor-Skriptunoff
Egor-Skriptunoff / how_to_install_lua_and_luajit_on_windows.md
Last active March 13, 2025 06:26
How to install Lua and LuaJIT on Windows

How to install Lua and LuaJIT on 64-bit Windows

  1. Download the latest Lua and LuaJIT sources

    • Create temporary folder for Lua sources.
      I assume you would use C:\Temp\ folder.

    • Visit Lua FTP webpage and download the latest Lua source archive, currently it is lua-5.4.3.tar.gz

  • Use suitable software (7-Zip, WinRar, WinZip or TotalCommander) to unpack the archive.
@msteen
msteen / print-lezer-tree.ts
Last active February 23, 2025 18:51
Print Lezer Trees
// MIT License
//
// Copyright (c) 2021 Matthijs Steen
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@na0x2c6
na0x2c6 / mic-toggle.applescript
Created May 12, 2021 08:10
Mic mute toggle script on Mac
-- refs: https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/ReadandWriteFiles.html
-- refs: https://medium.com/macoclock/how-in-the-bleep-do-i-mute-my-mic-anywhere-on-macos-d2fa1185b13
on writeTextToFile(theText, theFile, overwriteExistingContent)
try
set theFile to theFile as string
set theOpenedFile to open for access file theFile with write permission
if overwriteExistingContent is true then set eof of theOpenedFile to 0
write theText to theOpenedFile starting at eof
close access theOpenedFile