Navigation Menu

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
// std::bind() cannot bind std::weak_ptr.
// This file provides BindWeakPtr() which can bind a method with a std::weak_ptr.
// If the object inside weak_ptr is deleted, the function will become a NOP.
#include <iostream>
#include <functional>
#include <memory>
template <typename T>
class WeakFunction
{
@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
// ==UserScript==
// @name Stop gif animations on escape
// @namespace http://github.com/johan/
// @description Implements the "stop gif animations on hitting the escape key" feature that all browsers except Safari and Google Chrome have had since forever. Now also for Google Chrome!
// ==/UserScript==
document.addEventListener('keydown', freeze_gifs_on_escape, true);
function freeze_gifs_on_escape(e) {
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <unistd.h>
#include <stdbool.h>
#include <stdlib.h>
@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 / 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;