Skip to content

Instantly share code, notes, and snippets.

View andrewrk's full-sized avatar

Andrew Kelley andrewrk

View GitHub Profile
@andrewrk
andrewrk / README.md
Created August 28, 2023 19:00
exfiltrate groove basin database to a JSON file
  1. drop db2json.js into your groovebasin instance
  2. stop your groove basin instance so that it does not write to the db while you are dumping its data
  3. node db2json.js (use the same node.js version as groove basin is using, and it also wants to use the same leveldown dependency you already have installed). It hard-codes the input as groovebasin.db.
  4. groovebasin.db.json is created which is 100% of the information from the database, in JSON format. It is one giant map of every key-value pair.
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBFv8SrUBEADCku6WktTc1g+iyE9ZCtMv4kWqSHyQxFaEV8V5J2EAkjAzgr6w
NLmHGmNmXm8EzCWnwn/KfHJCeXTcgma/FtIF7hJfWB0xktA7WENUVc3qtT0cY9z3
9jh6J3TW3m9hcN7szSyEqGvPMVCvd5pERZXfof9OaRqtNak3GBOcklHYrVJ0KCtA
quR0t9NYrdOQikmBy4c9GaDsq/6H39LPuuj/vm7M+MHrw5dlKh+HPeUP9jMbFoXU
ohz97RSy8T2lUQDQx1EisAJNvdpU3mzAlWy2pEH+pKCBs5L0vPV/tvH1J5Pd489s
7VcdM9AolIuHvV0qCDAG7fcWujV5R5w48vznvfi6R3DN8O2iVrYdOWn2Bm60HdGm
XxGQswb6/MfThpFzQUNQpvnXxdbt2vefUTmM4suid6ki/jLfsiY1rqcNdEcriYFx
J6ma4SvZOB7OB2DG9bjWSItDIa2HqW37o//FYoFHJO0L+v5qjemYx5QrpL2wCpnY
@andrewrk
andrewrk / other-compiler_rt.zig.diff
Last active June 20, 2023 00:01
compiler_rt hacks for building musl libc.so with less symbol junk
--- a/lib/compiler_rt.zig
+++ b/lib/compiler_rt.zig
@@ -180,58 +180,58 @@ comptime {
_ = @import("compiler_rt/multc3.zig");
_ = @import("compiler_rt/divc3.zig");
- _ = @import("compiler_rt/divhc3.zig");
+ //_ = @import("compiler_rt/divhc3.zig");
_ = @import("compiler_rt/divsc3.zig");
_ = @import("compiler_rt/divdc3.zig");
@andrewrk
andrewrk / build.zig
Created February 20, 2023 16:20
sprinkling a little zig into a C project to help with debugging
const std = @import("std");
pub fn build(b: *std.Build) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
// Standard optimization options allow the person running `zig build` to select
@andrewrk
andrewrk / bootloader.zig
Created February 4, 2023 21:42
example of embedding a generated executable inside another one
pub export fn _start() void {}
@andrewrk
andrewrk / bench.zig
Last active January 5, 2023 03:24
benchmarking different versions of finding \r\n\r\n in a stream
const std = @import("std");
const KiB = 1024;
const MiB = 1024 * KiB;
pub fn main() !void {
var buffer: [(10000 / example.len) * example.len]u8 = undefined;
const total_bytes = 500000;
{
var i: usize = 0;
@andrewrk
andrewrk / foo.c
Created October 25, 2022 20:20
C backend output vs Zig code
static zig_E_Zir_Inst_Ref Sema_zirTypeName(zig_S_Sema * const a0, zig_S_Sema_Block * const a1, zig_u32 const a2) {
/* file:2:5 */
zig_S_Sema * t0;
t0 = a0;
zig_S_Sema * const * const t1 = (zig_S_Sema * const * )&t0;
zig_S_Sema * const t2 = (*t1);
zig_S_Zir * const t3 = (zig_S_Zir * )&t2->code;
zig_S_multi_array_list_MultiArrayList_28Zir_Inst_29_Slice * const t4 = (zig_S_multi_array_list_MultiArrayList_28Zir_Inst_29_Slice * )&t3->instructions;
zig_S_multi_array_list_MultiArrayList_28Zir_Inst_29_Slice const t5 = (*t4);
/* file:2:51 */
@andrewrk
andrewrk / README.md
Created September 1, 2022 02:31
rebase failing pull requests - useful when your contributors unfortunately open PRs against a broken master branch

Rebase Failing Pull Requests

Dependencies

  • gh with a logged in user
  • git clone zig repo in zig
  • jq, date, and git in PATH.

Instructions

@andrewrk
andrewrk / 0trace.zig
Last active June 7, 2022 22:04
a new std.debug.Trace API
pub fn Trace(comptime size: usize, comptime stack_frame_count: usize) type {
return struct {
addrs: [size][stack_frame_count]usize = undefined,
notes: [size][]const u8 = undefined,
index: usize = 0,
const frames_init = [1]usize{0} ** stack_frame_count;
pub noinline fn add(t: *@This(), note: []const u8) void {
return addAddr(t, @returnAddress(), note);
package main
import "fmt"
type Update struct{}
type Handler func(*Update)
type Dispatcher struct {
handlers []Handler
}