Skip to content

Instantly share code, notes, and snippets.

@fcamel
fcamel / benchmark_zip_range.py
Created August 25, 2023 05:47
benchmark range + array index vs. zip
# Result on Mac Mini M2 Pro:
#
# use_range returns 199999
# use_range_local returns 199999
# use_zip returns 199999
# use_range: 10.198090834077448
# use_range_local: 8.507670041057281
# use_zip: 6.672960666939616
import timeit
@fcamel
fcamel / active.go
Last active April 4, 2022 15:20
active object pattern in go
package main
import "fmt"
type One int
type Ten int
type work struct {
object interface{}
result chan error
@fcamel
fcamel / LD_DEBUG_symbols.sh
Last active July 22, 2018 14:44
Example of LD_DEBUG=symbols
$ LD_LIBRARY_PATH=. ./prog
foo
foo-xyz
bar
foo-xyz
$ LD_DEBUG=symbols LD_LIBRARY_PATH=. ./prog
...
foo
21169: symbol=xyz; lookup in file=./prog [0]
21169: symbol=xyz; lookup in file=./libfoo.so [0]
@fcamel
fcamel / LD_DEBUG_libs.sh
Last active July 22, 2018 14:23
Example of LD_DEBUG=libs
$ LD_DEBUG=libs out/Debug/chrome
30970: find library=libpthread.so.0 [0]; searching
30970: search path=/home/fcamel/dev/chromium/src/out/Debug/./tls/x86_64:/home/fcamel/dev/chromium/src/out/Debug/./tls:/home/fcamel/dev/chromium/src/out/Debug/./x86_64:/home/fcamel/dev/chromium/src/out/Debug/. (RPATH from file out/Debug/chrome)
30970: trying file=/home/fcamel/dev/chromium/src/out/Debug/./tls/x86_64/libpthread.so.0
30970: trying file=/home/fcamel/dev/chromium/src/out/Debug/./tls/libpthread.so.0
30970: trying file=/home/fcamel/dev/chromium/src/out/Debug/./x86_64/libpthread.so.0
30970: trying file=/home/fcamel/dev/chromium/src/out/Debug/./libpthread.so.0
30970: search cache=/etc/ld.so.cache
30970: trying file=/lib/x86_64-linux-gnu/libpthread.so.0
30970:
@fcamel
fcamel / ldd_example.sh
Created July 22, 2018 12:03
ldd example
$ ldd /bin/ls
linux-vdso.so.1 => (0x00007ffe7a5fe000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007fd64b7a1000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd64b3d7000)
libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007fd64b167000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fd64af63000)
/lib64/ld-linux-x86-64.so.2 (0x00007fd64b9c3000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fd64ad46000)
@fcamel
fcamel / elf_shared_lib_order.sh
Created July 21, 2018 16:38
ELF shared library order
$ cat prog.c
#include <stdio.h>
void foo();
void bar();
int main(void) {
foo();
bar();
return 0;
@fcamel
fcamel / elf_visibility_test.sh
Last active July 29, 2018 02:48
ELF visibility test
$ cat prog.c
#include <stdio.h>
void func();
void xyz() {
printf("main-xyz\n");
}
void xyz2() {
@fcamel
fcamel / benchmark_gzip_brotli.sh
Created February 5, 2018 08:30
benchmark gzip / brotli
#!/bin/bash
rm -rf output
mkdir output
ls -l input | awk '{ s += $5 } END { print s }'
# compress
begin=$(date +%s%N)
for f in input/*
@fcamel
fcamel / skia_stap_output.txt
Created January 7, 2018 07:41
SystemTap output for Skia viewer
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("SkAutoCanvasRestore@../../include/core/SkCanvas.h:2788").call
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("getSaveCount@../../src/core/SkCanvas.cpp:874").call
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("SkCanvas@../../src/core/SkCanvas.cpp:710").call
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("init@../../src/core/SkCanvas.cpp:629").call
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("MCRec@../../src/core/SkCanvas.cpp:296").call
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("DeviceCM@../../src/core/SkCanvas.cpp:256").call
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("qr_clip_bounds@../../src/core/SkCanvas.cpp:606").call
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("setSurfaceBase@../../include/core/SkCanvas.h:2663").call
process("/home/fcamel/dev/study/skia/out/Debug/viewer").function("save@../../src/core/
@fcamel
fcamel / gist:878c843badde0d177c57734d0094ac01
Last active January 6, 2018 09:13
strace -f -s 1024 host ubuntu
[pid 32630] socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP) = 6
[pid 32630] fcntl(6, F_DUPFD, 20) = 20
[pid 32630] close(6) = 0
...
[pid 32630] bind(20, {sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("0.0.0.0")}, 16) = 0
...
[pid 32630] sendmsg(20, {msg_name(16)={sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.1.1")}, msg_iov(1)=[{"J\311\1\0\0\1\0\0\0\0\0\0\6ubuntu\0\0\1\0\1", 24}], msg_controllen=0, msg_flags=0}, 0 <unfinished ...>
...
[pid 32630] recvmsg(20, {msg_name(16)={sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.1.1")}, msg_iov(1)=[{"J\311\200\200\0\1\0\1\0\0\0\0\6ubuntu\0\0\1\0\1\300\f\0\1\0\1ZQ\1\343\0\4\300\250\1j", 65535}], msg_controllen=56, [{cmsg_len=32,
...