Skip to content

Instantly share code, notes, and snippets.

@twleung
twleung / mozlz4a.py
Created December 20, 2022 19:10 — forked from Tblue/mozlz4a.py
MozLz4a compression/decompression utility
#!/usr/bin/env python3
# vim: sw=4 ts=4 et tw=100 cc=+1
#
####################################################################################################
# DESCRIPTION #
####################################################################################################
#
# Decompressor/compressor for files in Mozilla's "mozLz4" format. Firefox uses this file format to
# compress e. g. bookmark backups (*.jsonlz4).
#
@twleung
twleung / roam_wp
Created July 22, 2020 02:15 — forked from pmbauer/roam_wp
roam weekly plan
#/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
roam_date() {
date -d "${*}" '+%B %eXX, %Y' \
| sed -e 's/11XX/11th/; s/12XX/12th/; s/13XX/13th/' \
-e 's/1XX/1st/; s/2XX/2nd/; s/3XX/3rd/' \
-e 's/XX/th/; s/ / /'
}
@twleung
twleung / latency_numbers.md
Created March 28, 2019 21:07 — forked from GLMeece/latency_numbers.md
Latency Numbers Every Programmer Should Know - MarkDown Fork

Latency Comparison Numbers

Note: "Forked" from Latency Numbers Every Programmer Should Know

Event Nanoseconds Microseconds Milliseconds Comparison
L1 cache reference 0.5 - - -
Branch mispredict 5.0 - - -
L2 cache reference 7.0 - - 14x L1 cache
Mutex lock/unlock 25.0 - - -
@twleung
twleung / latency.txt
Created March 28, 2019 20:54 — forked from jboner/latency.txt
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
Verifying that "twleung.id" is my Blockstack ID. https://explorer.blockstack.org/name/twleung.id
Verifying my Blockstack ID is secured with the address 1NBhrFcfhiY9TmkrK2X3ykbeHRqC7atMAM https://explorer.blockstack.org/address/1NBhrFcfhiY9TmkrK2X3ykbeHRqC7atMAM
@twleung
twleung / impbcopy.m
Created May 3, 2017 22:30 — forked from mwender/impbcopy.m
Command line copy an image file to the clipboard in Mac OS X. See first comment for install instructions.
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <unistd.h>
BOOL copy_to_clipboard(NSString *path)
{
// http://stackoverflow.com/questions/2681630/how-to-read-png-image-to-nsimage
NSImage * image;
if([path isEqualToString:@"-"])
{
// http://caiustheory.com/read-standard-input-using-objective-c
### Keybase proof
I hereby claim:
* I am twleung on github.
* I am twleung (https://keybase.io/twleung) on keybase.
* I have a public key whose fingerprint is E6E8 48D5 17E6 0484 37D6 B38E 6028 D6FC 9D3A FD4F
To claim this, I am signing this object:
Verifying that +twleung is my Bitcoin username. You can send me #bitcoin here: https://onename.io/twleung