Skip to content

Instantly share code, notes, and snippets.

View bonzini's full-sized avatar

Paolo Bonzini bonzini

View GitHub Profile
#!/bin/sh
#
# git-snapshot.sh - save junk code to a snapshots branch
#
# USAGE: git-snapshot.sh [-m message] [files...]
#
# Run `git add files` and then create a new commit on branch 'snapshot'
# with two parents, the previous snapshot and HEAD.
#
# If -m is given, the 'message' is used as the commit message; otherwise
@bonzini
bonzini / life.md
Created January 17, 2012 08:11
Rotozooming game of life, with blur in 256 bytes

; Roto-life (rotozooming game of life, with blur -- in 256 bytes!)
; Game of life algorithms by INT-E
; Decyphering and adaptation of game of life, and everything else by Bonz
@bonzini
bonzini / gtest_main.py
Created January 17, 2012 13:48
Integrating PyUnit and gtester
#! /usr/bin/env python
#
# GTester-compatible main program for pyunit
#
# Copyright (C) 2011 Red Hat, Inc.
# Author: Paolo Bonzini <[email protected]>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
from datetime import date
# per ogni festa che cade di:
# sabato, domenica, -1 punto (niente ponte e niente festa)
# giovedi', martedi', +4 punti (ponte!!)
# lunedi', venerdi', +3 punti (festa dopo fine settimana)
# mercoledi +1 punti (solo festa)
punteggio = [3, 4, 1, 4, 3, -1, -1]
feste = [(1,1), # capodanno
(6,1), # epifania
@bonzini
bonzini / bdd.py
Last active August 29, 2015 14:10
BDD library in Python
# Copyright 2014 Paolo Bonzini
# API inspired by py-simple-bdd.
# License: X11 (MIT)
class Variable(object):
def __init__(self, name):
self._name = name
self._hash = hash(name)
self._node = Node(self, Node.T, Node.F)
@bonzini
bonzini / pyyaml-split.py
Last active August 29, 2015 14:10
Splitting YAML "directives" from other events, and passing the others down to yaml.load
__all__ = [ 'EventBasedLoader', 'EventBasedSafeLoader' ]
from yaml.composer import Composer
from yaml.constructor import Constructor, SafeConstructor
from yaml.resolver import Resolver
import yaml
# Replacement for Scanner+Parser that replays events from a stream. These
# four methods seem to be the entire interface that Composer expects.
class EventBasedParser(object):
@bonzini
bonzini / memeqzero.c
Last active January 17, 2024 17:50
Optimizing "is this memory block equal to zero?"
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define N 100000
char buf1[1024], buf2[1024], buf3[1024], buf4[65536];
static __attribute__((noinline)) bool memeqzero1(const void *data, size_t length)
{
@bonzini
bonzini / exec-hook.c
Created August 10, 2017 12:26
An LD_PRELOAD library that waits for a given binary to be exec-ed, and forces it under a gdbserver
/* Copyright (C) 2012-2017 by László Nagy
Copyright (C) 2017 Paolo Bonzini
This file is based on Bear.
It is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
@bonzini
bonzini / patchew.md
Last active March 9, 2018 19:52
Prototype patchew documentation

Patchew design and flow

Patchew is designed around three components:

  • a web server, which hosts the Patchew user interface and also exposes API endpoints for use from the other parts;

  • one or more importers, which read email from an IMAP server, send them to the server, and pushes the messages to a git tree;

@bonzini
bonzini / tilix.dconf
Last active March 12, 2018 08:32
My tilix configuration (dconf load /com/gexperts/Tilix/)
[/]
new-window-inherit-state=true
use-overlay-scrollbar=true
terminal-title-style='small'
theme-variant='light'
session-name='${title}'
use-tabs=true
new-instance-mode='new-session'
enable-wide-handle=false
app-title='${terminalNumber}: ${sessionName}'