Skip to content

Instantly share code, notes, and snippets.

--------------------------------------------------------------------------------
Command: target/profiling/am-repro
Massif arguments: --time-unit=B
ms_print arguments: massif.out.9109
--------------------------------------------------------------------------------
GB
12.66^ #
| @@@#
--------------------------------------------------------------------------------
Command: target/profiling/am-repro
Massif arguments: (none)
ms_print arguments: massif.out.3715
--------------------------------------------------------------------------------
MB
45.81^ #
| @@#:
@josephg
josephg / README.md
Created February 4, 2019 21:54
Foundationdb C API example

This is a simple example program using the foundationdb C API. Its written & tested on macos; but it should be easy to adapt to work on BSD / linux.

This also demonstrates using libuv to integrate foundationdb into a run loop. Promises are run in the main libuv loop.

Compile with

$ clang test.c -Wall -lfdb_c -I/usr/local/include -luv
@josephg
josephg / 0dedict.py
Last active April 28, 2024 14:07
Apple dictionaries
# Thanks to commenters for providing the base of this much nicer implementation!
# Save and run with $ python 0dedict.py
# You may need to hunt down the dictionary files yourself and change the awful path string below.
# This works for me on MacOS 10.14 Mohave
from struct import unpack
from zlib import decompress
import re
filename = '/System/Library/Assets/com_apple_MobileAsset_DictionaryServices_dictionaryOSX/9f5862030e8f00af171924ebbc23ebfd6e91af78.asset/AssetData/Oxford Dictionary of English.dictionary/Contents/Resources/Body.data'
f = open(filename, 'rb')
@josephg
josephg / graph.py
Last active March 7, 2024 09:27
Graph diff
from dataclasses import dataclass
from enum import Enum
import heapq
Version = set[int] # The numbers in this set are indexes into the list of events in the graph.
@dataclass
class GraphEntry:
parents: set[int] # Set of indexes...
id: any
@josephg
josephg / README.md
Last active March 7, 2024 06:58
Getting Zig compiling to WASM

In case anyone else wants to play with Zig on webassembly, here's what you need to do to make it work on a mac today.

1. Get LLVM 7 compiled with webassembly support.

You'll need LLVM to output to the WASM target. This has just been added by default in trunk, so if LLVM >7 is available, you might be able to just brew install llvm.

If you have wasm support already you should see:

$ llc --version
@josephg
josephg / bench-automerge.js
Last active March 4, 2024 19:03
benchmark code from blog post
// Run with node --expose-gc bench.js ../automerge-paper.json.gz
// automerge-paper.json.gz from https://github.com/josephg/crdt-benchmarks
// Read in a patch file and check that the patches all apply correctly.
const fs = require('fs')
const assert = require('assert')
const zlib = require('zlib')
const automerge = require('automerge')
const v8 = require('v8')
@josephg
josephg / main.c
Created August 26, 2017 08:20
kqueue network & file example
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/event.h>
#include <netdb.h>
#include <assert.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
@josephg
josephg / Cargo.toml
Last active April 28, 2023 12:55
benchmark automerge complex trace
[package]
name = "automerge-test"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
automerge = "0.4.1"
serde = { version = "1.0.160", features = ["derive"] }
~/temp $ mkdir a
~/temp $ cd a
~/temp/a $ git init
Initialized empty Git repository in /home/seph/temp/a/.git/
~/temp/a:master ✓ $ cat > foo
asdf
~/temp/a:master ✓ $ git add foo
~/temp/a:master ✗ $ git commit -m 'initial import'
[master (root-commit) 7fe725a] initial import