Skip to content

Instantly share code, notes, and snippets.

@davidcelis
davidcelis / README.md
Last active May 23, 2023 07:41
Watch for changes in a slow monorepo and update a `git status` cache for your prompt to read from 😬

A git prompt hack for the impatient amongst us

Maybe you have a big ol' monorepo, and git operations are pretty slow in it. For those of us who like to show information about the repository's dirty status in our prompt, that means a slow prompt. Waiting 1s every time you hit the return key can really add up! Instead of just giving up and eschewing the dirty status entirely, why not just cache it in the background have your prompt read from the cache?

Prerequisites

First, install fswatch:

brew install fswatch
@borbit
borbit / redis_cas.js
Last active March 3, 2021 11:46
CAS implementation for Redis.
var LUA_GETS =
'return {'
+ 'redis.call(\'get\', KEYS[1]),'
+ 'redis.call(\'get\', KEYS[1]..\'_ver\')'
+ '}';
var LUA_CAS =
'local ver = redis.call(\'get\', KEYS[1]..\'_ver\') '
+ 'if not ver or ver == KEYS[3] '
+ 'then '
@jboner
jboner / latency.txt
Last active May 7, 2024 19:39
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD