Skip to content

Instantly share code, notes, and snippets.

@pkhuong
pkhuong / clang.s
Last active October 5, 2024 19:59
BAD TEST CASE REDUCTION ON MY END
.file "foo.c"
.globl foo // -- Begin function foo
.p2align 2
.type foo,@function
foo: // @foo
.cfi_startproc
// %bb.0:
movi v0.2d, #0000000000000000
//APP
//first use v0
@pkhuong
pkhuong / ppp_lock.rs
Last active April 26, 2024 13:24
Fast path for single-owner Arc<Mutex>
//! The `ppp_lock` module defines traits to access the value in a [`Arc<Mutex<T>>`]
//! with higher-order [`Update<T>::update`] or [`TryUpdate<T>::try_update`]
//! methods. The higher-order interface lets the methods implement a fast path
//! for single-reference mutable (i.e., exclusively owned) [`Arc`]s.
//!
//! Using the `ppp_lock` traits avoids atomics for private owners (single-reference
//! `&mut Arc<Mutex<T>>`), while incurring marginal additional overhead when the
//! object is actually shared (multi-reference `Arc`)... and the traits, with their
//! higher-order methods, complicate access compared to regular locking.
//!
@pkhuong
pkhuong / yannakakis.md
Last active November 8, 2024 15:56
A minimal version of Yannakakis's algorithm for mostly plain Python
#!/usr/bin/env sed -re s|^|\x20\x20\x20\x20| -e s|^\x20{4}\x23\x23{(.*)$|<details><summary>\1</summary>\n| -e s|^\x20{4}\x23\x23}$|\n</details>| -e s|^\x20{4}\x23\x23\x20?|| -e s|\x0c|\x20|
license, imports
# Yannakakis.py by Paul Khuong
#
# To the extent possible under law, the person who associated CC0 with
# Yannakakis.py has waived all copyright and related or neighboring rights
# to Yannakakis.py.

@pkhuong
pkhuong / README.md
Created May 3, 2021 15:39 — forked from parsley42/README.md
Chromebook ssh-agent setup

Setting up ssh-agent in Linux/Crostini on Chromebook

  • Create your user systemd directory:
$ mkdir -p .config/systemd/user
  • Edit the unit file .config/systemd/user/ssh-agent.service:
[Unit]
Description=SSH key agent
@pkhuong
pkhuong / 00RECORD_STREAM.md
Last active January 11, 2021 17:09
Word-stuffed record stream

Backtrace's log record framing format

We use this self-synchronising format to store key metadata for our server-side embedded crash database. See this blog post for more details and explanations.

We released the source under the MIT license, but the scheme is simple enough that coding an interface tuned to one's specific needs probably makes sense.

@pkhuong
pkhuong / kmv_ci.py
Last active September 25, 2020 21:13
Numerical implementation of Beyer et al's confidence intervals for k min values
"""Numerical implementation of Beyer et al's confidence intervals for k min values
[On Synopses for Distinct-Value Estimation Under Multiset Operations](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.230.7008&rep=rep1&type=pdf#page=6), Section 4.3.
ci_probability(k, eps) computes the probability that the unbiased
cardinality estimate
\hat{D}_k^{UB} = (k - 1) / U(k),
where k is the number of minimum values we keep, and U(k) is the
@pkhuong
pkhuong / bridgetc_digit_update_1.inc
Last active May 24, 2020 00:27
BridgeTC: a bridge from C types to C singleton values
/* -*- mode: C -*- */
#if BRIDGETC_IMPL_DIGIT_1 == 0
# undef BRIDGETC_IMPL_DIGIT_1
# define BRIDGETC_IMPL_DIGIT_1 1
# undef BRIDGETC_IMPL_SEARCH_1
# define BRIDGETC_IMPL_SEARCH_1 BRIDGETC_IMPL_SEARCH_1_1
#elif BRIDGETC_IMPL_DIGIT_1 == 1
# undef BRIDGETC_IMPL_DIGIT_1
# define BRIDGETC_IMPL_DIGIT_1 2
# undef BRIDGETC_IMPL_SEARCH_1
"""Too many ways to generate pairs of two integers in ascending
order.
"""
from hypothesis import assume, given
import hypothesis.strategies as st
import unittest
class TestAscending(unittest.TestCase):
@pkhuong
pkhuong / LICENCE
Last active December 15, 2021 23:25
MIT-licensed support code for coverage-guided Hypothesis testing
Copyright 2020 Paul Khuong, Backtrace I/O, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWAR
@pkhuong
pkhuong / signal-on-instruction-count.c
Created February 18, 2020 02:21
Trigger a unix signal based on the HW instruction counter PMC
#define RUN_ME /*
exec cc -g -ggdb -O2 -W -Wall -std=c99 $0 -o "$(basename $0 .c)"
*/
/*
* Copyright 2020 Paul Khuong
* SPDX-License-Identifier: BSD-2-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions