Skip to content

Instantly share code, notes, and snippets.

View philsquared's full-sized avatar

Phil Nash philsquared

View GitHub Profile
SCENARIO("initialize rewind", "[rewind]") {
GIVEN( "an uninitialised environment") {
int rc;
MDB_env *env;
MDB_dbi dbi;
MDB_txn *txn;
WHEN("an environment is created and opened") {
REQUIRE(SuccessFrom(mdb_env_create(&env)));
REQUIRE(SuccessFrom(mdb_env_set_mapsize(env, size_t(1048576000))));
@philsquared
philsquared / rewind-sections.cpp
Created January 14, 2019 10:09
Kellabyte's rewind tests using plain SECTIONs (depends on https://gist.github.com/philsquared/567fdd233d574fe1957d17aff3e5d02c)
TEST_CASE("initialize rewind", "[rewind]") {
int rc;
MDB_env *env;
MDB_dbi dbi;
MDB_txn *txn;
SECTION("create and open an environment") {
REQUIRE(SuccessFrom(mdb_env_create(&env)));
REQUIRE(SuccessFrom(mdb_env_set_mapsize(env, size_t(1048576000))));
@philsquared
philsquared / SquarePeg.rs
Last active May 5, 2021 10:54
Fitting a SquarePeg into a RoundHole, in Rust
trait Square {
fn size(&self) -> f64;
fn perimeter(&self) -> f64;
}
trait Circle {
fn radius(&self) -> f64;
fn perimeter(&self) -> f64;
}
@philsquared
philsquared / toc_adder.py
Last active January 17, 2026 12:54
A simple script to reverse engineer a table of contents from PDFs with a fairly standard numbered heading system, and add the TOC into (a copy of) the PDFs
import fitz # needs: pip install pymupdf
import re
import sys
import glob
import os
def extract_toc_from_pdf(pdf_path, output_path=None):
"""
Extract table of contents from PDF based on large bold headings.