Skip to content

Instantly share code, notes, and snippets.

View zeusdeux's full-sized avatar
👾
i wear my sunglasses at night so i can — so i can justify the money spent on 'em

Mudit zeusdeux

👾
i wear my sunglasses at night so i can — so i can justify the money spent on 'em
View GitHub Profile
@zeusdeux
zeusdeux / main.go
Last active October 21, 2025 11:20
Faster 1brc local data generation (~1m on i7 + SSD from 2020)
// Authors: http://github.com/ctbur and http://github.com/zeusdeux
// Copyright 2025-forever
// Do whatever you want with the source. Make sure to attribute http://github.com/ctbur and http://github.com/zeusdeux
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package main
import (
"bufio"
"flag"
@zeusdeux
zeusdeux / force-opt.js
Created October 6, 2025 23:36
Using node intrinsics to force optimizations
// node --allow-natives-syntax --print-opt-code --trace-deopt force-opt.js
function test(x) { return 1 + Math.sin(x) }
%PrepareFunctionForOptimization(test);
test(0.5); test(0.6);
%OptimizeFunctionOnNextCall(test);
test(0.7);
%FinalizeOptimization();
%GetOptimizationStatus(test);
@zeusdeux
zeusdeux / osx-ld.md
Created July 28, 2024 16:27 — forked from loderunner/osx-ld.md
potential blog posts

ld – Wading through Mac OS X linker hell

Intro

Friend: I tried looking at static linking in Mac OS X and it seems nearly impossible. Take a look at this http://stackoverflow.com/a/3801032

Me: I have no idea what that -static flag does, but I'm pretty sure that's not how you link to a library. Let me RTFM a bit.

Minutes later...

@zeusdeux
zeusdeux / build_zdx.sh
Created June 16, 2024 01:25
Build static universal raylib as libraylib.a on macos (libraylib.a)
#! /bin/sh
set -e
function build_raylib_macos {
curr_dir="$(basename $(pwd))"
if [[ "$curr_dir" != "src" ]];
then
@zeusdeux
zeusdeux / hello.s
Last active May 6, 2024 01:13
M1 macOS ARM64 assembly (Darwin Kernel syscalls) — Hello World
.global _start
.align 2
.text
;;; COMPILE and RUN CMD:
;;; as -o hello.o hello.s && ld -macos_version_min 14.0.0 -o hello.bin hello.o -e _start -arch arm64 && ./hello.bin
;;;
;;; EXTRACT FLAT (PURE) BINARY:
;;; 1. otool -l hello.bin and search for sectname __text > offset field (it's in decimal not hex btw)
;;; 1a. Take the offset, convert to hex and verify code starts there in the hexdump view of the compiled binary
@zeusdeux
zeusdeux / click-outside.ts
Last active May 26, 2023 15:07
Non-💩 and dirt simple click-outside directive for Vue 3
import type { Directive } from "vue";
type ClickOutsideHandler = ($event: MouseEvent | TouchEvent) => void;
type ClickOutsideHandlerMap = Map<HTMLElement, ClickOutsideHandler> & {
initialized?: boolean;
};
const clickOutsideHandlersSymbol: symbol = Symbol.for("v-click-outside-handlers");
// @ts-ignore
@zeusdeux
zeusdeux / fail-on-select-console-calls.ts
Last active May 24, 2023 17:05
Cleaner console for jest test runs + fail on certain console messages
/**
* Fail jest test run if certain messages are logged to console (e.g., `[vuex warn] unknown getter: ....`)
* Conditionally (on CI or not) add this file and the file below to `setupFilesAfterEnv` in jest config.
*
* Example config:
*
* import type { Config } from "@jest/types"
*
* const config: Config.InitialOptions = {
* ...
@zeusdeux
zeusdeux / timed.ts
Created April 21, 2023 20:15
A function that runs async functions and prints how long they take to stderr with a given string as the prefix message
export async function timed<T>(
cb: () => Promise<T>,
message: string,
debug = (...args: any[]) => console.warn(...args),
): ReturnType<typeof cb> {
const start = performance.now();
const result = await cb();
const end = performance.now();
let timeSpent = end - start;
@zeusdeux
zeusdeux / filter-utility.ts
Last active October 17, 2022 15:23
Filtering keys from an object type based on type of value for the keys
type MixedObject = {
someFn(x: number): string
someProp: symbol
}
// using key remapping that was added in TS 4.1 wherein
// if we return `never` as a value for key in the remapping logic
// the key is dropped from the resulting type
// More: https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#key-remapping-via-as
type Filter<InputType, AllowedValueTypes> = {
@zeusdeux
zeusdeux / doSet.js
Last active May 29, 2022 22:43
Persistent set operation
function assert(cond, msg) {
if (!cond) throw new Error(msg)
}
function doSet(source, pathToSet, newValue) {
assert(Array.isArray(pathToSet), 'path being set needs to be given as an array of prop names in order of access')
const prop = pathToSet.shift()
if (typeof prop === 'undefined') {