Skip to content

Instantly share code, notes, and snippets.

View bonzini's full-sized avatar

Paolo Bonzini bonzini

View GitHub Profile
gh api graphql -F owner=mesonbuild -F name=meson -Fmilestone=115 -f query='\
query($name: String!, $owner: String!, $milestone: ID!) {
repository(owner: $owner, name: $name) {
milestone(number: $milestone) {
pullRequests(last: 100, states: OPEN) {
edges {
node {
title
number
url
@bonzini
bonzini / bits.rs
Last active December 3, 2024 15:55
recursive descent parser in a procedural macro
/// # Definition entry point
///
/// Define a struct with a single field of type $type. Include public constants
/// for each element listed in braces.
///
/// The unnamed element at the end, if present, can be used to enlarge the set of
/// valid bits. Bits that are valid but not listed are treated normally for
/// the purpose of arithmetic operations, and are printed with their hexadecimal
/// value.
///
use std::marker::PhantomPinned;
use std::mem::MaybeUninit;
use std::os::raw::c_void;
// ----------------------------------------
/// A callback to a logging function `f`.
/// This would ordinarily be provided by C code.
pub struct LogRegistration {
f: fn(&str, *mut c_void),
@bonzini
bonzini / gcd.h
Last active April 14, 2024 08:49
// result for blog post on my machine
// 10.7 Ma/s 93.60 ns/d 4.17 GHz 390.21 c/d 778.90 i/d 24.39 c/b 48.68 i/b 2.00 i/c
// ^^^^^^^^
//
// binary_gcd_paolo_1 wins for #instructions, but is really bad in terms of ipc
// 5.3 Ma/s 189.59 ns/d 4.16 GHz 788.92 c/d 324.72 i/d 49.31 c/b 20.30 i/b 0.41 i/c
// ^^^^^^^^^^
//
// binary_gcd_paolo_2 wins overall on my machine, saving more in #instructions than it loses ipc
// 12.0 Ma/s 82.99 ns/d 4.15 GHz 344.06 c/d 592.35 i/d 21.50 c/b 37.02 i/b 1.72 i/c
@bonzini
bonzini / userChrome.css
Created November 30, 2022 17:42
teaks for a dark(er) thunderbird theme
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
#titlebar {
height: 44px;
}
#navigation-toolbox, #tabmail-tabs, #tabmail-arrowscrollbox { /* Outer tab containers */
min-height: 44px !important;
}
@bonzini
bonzini / click.yaml
Last active November 30, 2022 17:44
Home Assistant blueprints
blueprint:
name: Personal Zone Notification
description: Send a notification with a URL to a device when it enters a specific zone.
domain: automation
input:
zone:
name: Zone
description: Zone triggering the notification
selector:
entity:
@bonzini
bonzini / gnome-sendmail.py
Created May 4, 2022 17:53
gnome-sendmail.py
#! /usr/bin/env python3
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# Command line access to GNOME Online Accounts mail accounts
#
# Authors:
# Daniel P. Berrange <[email protected]>
# Paolo Bonzini <[email protected]>
@bonzini
bonzini / coro.cc
Last active March 11, 2022 21:39
Simple C++ coroutine runtime
#include "coro.h"
#include <cstdio>
static __thread Coroutine *current;
void Yield::await_suspend(std::coroutine_handle<> parent) const noexcept {
//printf("!!!! top = %p, yielding from %p\n", current->top, parent);
current->top = parent;
}
@bonzini
bonzini / mqtt.py
Last active March 2, 2022 09:32
termostato con zigbee2mqtt
#! /usr/bin/env python3
from collections import defaultdict
import asyncio
import paho.mqtt.client
import json
import weakref
class ActiveSubscription:
def __init__(self, topic, obj, client):
@bonzini
bonzini / patchew-ty
Last active February 25, 2022 14:52
#! /bin/sh
if test $1 = -n; then
ARGS=--dry-run
shift
else
ARGS=--confirm=always
fi
mboxsplit() {