Skip to content

Instantly share code, notes, and snippets.

View tavianator's full-sized avatar
💭
𝒪(𝑛) things to do, 𝒪(lg 𝑛) time to do them

Tavian Barnes tavianator

💭
𝒪(𝑛) things to do, 𝒪(lg 𝑛) time to do them
View GitHub Profile
@tavianator
tavianator / perf-cmp.py
Created November 6, 2024 22:01
Compare perf stat between programs
#!/usr/bin/env python3
import argparse
import json
import os
import re
from scipy.stats import ttest_ind_from_stats
from subprocess import DEVNULL, Popen
import sys
@tavianator
tavianator / README.md
Created November 29, 2023 18:24
GitHub markdown tricks

GitHub markdown tricks


The above heading with badges aligned with the horizontal rule is made with this code:

@tavianator
tavianator / lib.rs
Created August 26, 2022 22:27
termtx
//! Lorem ipsum.
#![deny(missing_docs)]
use rustix::fd::{AsFd, AsRawFd, BorrowedFd, IntoFd, IntoRawFd, OwnedFd, RawFd};
use rustix::fs::{cwd, fcntl_dupfd_cloexec, fcntl_getfl, fstat, openat, Mode, OFlags, Stat};
use rustix::io::OwnedFd as RustixFd;
use rustix::io::{poll, read, write, Errno, PollFd, PollFlags};
use rustix::path::Arg;
use rustix::termios::{
@tavianator
tavianator / remote
Created May 27, 2022 20:59
Remote access mkinitcpio hook
#!/bin/bash
add_user() {
getent passwd "$1" >>"$BUILDROOT/etc/passwd"
getent shadow "$1" >>"$BUILDROOT/etc/shadow"
getent group "$(id -Gn "$1")" >>"$BUILDROOT/etc/group"
}
build() {
add_systemd_unit cryptsetup-pre.target
@tavianator
tavianator / keybase.md
Created December 3, 2020 14:50
keybase.md

Keybase proof

I hereby claim:

  • I am tavianator on github.
  • I am tavianator (https://keybase.io/tavianator) on keybase.
  • I have a public key whose fingerprint is 76F5 CE72 4EDE CE11 1DE3 5E27 938E 1B24 4D3D B9E1

To claim this, I am signing this object:

@tavianator
tavianator / Makefile
Created July 27, 2020 20:45
partymix
partymix_ui.py: partymix.ui
pyuic4 partymix.ui >partymix_ui.py
@tavianator
tavianator / README
Created November 1, 2016 16:51
NDK bug 176 reproducer
Apologies for the gcc-based test case! But clang chokes on linking the same .s file, so I suspect it's not a gcc-specific bug.
$ arm-linux-androideabi-g++ -std=c++11 -fpic -O3 -flto -Ipath/to/boost -c foo.cpp
$ arm-linux-androideabi-g++ -shared foo.o -lc++_shared -o foo.so -save-temps
/tmp/ndk-arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /tmp/ndk-arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/libgcc.a(pr-support.o): multiple definition of '__gnu_unwind_frame'
/tmp/ndk-arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: /tmp/ndk-arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/lib/libunwind.a(Unwind-EHABI.o): previous definition here
/tmp/ndk-arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /tmp/ndk-arm/bin/../lib/gcc/arm-linux-androideabi/4.9.x/libgcc.a(pr-support.o): multiple definition of '_Unwind_GetRegionStart'
/tmp/ndk-arm/bin/../lib/gcc/
@tavianator
tavianator / ray_box.c
Last active May 1, 2022 14:12
Ray/bounding box intersection test program
/****************************************************************************
* Copyright (C) 2015 Tavian Barnes <[email protected]> *
* *
* Permission to use, copy, modify, and/or distribute this software for any *
* purpose with or without fee is hereby granted. *
* *
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES *
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF *
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR *
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES *
From ef19df89a9ee7be2d9c092bcc24cd80a79d35499 Mon Sep 17 00:00:00 2001
From: Tavian Barnes <[email protected]>
Date: Wed, 7 Jan 2015 16:32:51 -0500
Subject: [PATCH 1/1] Don't trust the bytesConsumed() value from
SSLEngine.unwrap().
Android 5.0 always returns 0 instead of the actual number of bytes.
Compute it from the byte buffer positions instead.
https://code.google.com/p/android/issues/detail?id=93740
@tavianator
tavianator / gist:65f8642a5b859d6cb181
Last active August 29, 2015 14:03
Output of gcc -std=c11 -O3 -fopt-info-all-vec -S slp-test.c
slp-test.c:8:17: note: ===vect_slp_analyze_bb===
slp-test.c:8:17: note: === vect_analyze_data_refs ===
slp-test.c:8:17: note: got vectype for stmt: _4 = x0_3(D)->z;
vector(2) double
slp-test.c:8:17: note: got vectype for stmt: _7 = n_6(D)->z;
vector(2) double
slp-test.c:8:17: note: got vectype for stmt: _9 = x0_3(D)->x;
vector(2) double
slp-test.c:8:17: note: got vectype for stmt: _10 = n_6(D)->x;
vector(2) double