Skip to content

Instantly share code, notes, and snippets.

@mcejp
mcejp / bsod.php
Created September 14, 2023 12:51
BSOD-style error page in PHP
View bsod.php
<!doctype html>
<html>
<head>
<style>
html {
font-size: 1.2em;
}
body {
@mcejp
mcejp / _README.md
Last active September 8, 2023 19:25
My baseline setup for Python package projects
View _README.md
@mcejp
mcejp / saveregister.S
Created July 30, 2023 10:28
Saving registers on Aarch64 in a core-dump-ready format
View saveregister.S
.macro saveregister
// Registers are saved in the following order (see also: user_regs_struct):
// x0 x1 ... x28 x29 x30 SP PC PSTATE
// at: -110 -108 ... -30 -28 -20 -18 -10 -08 (hex) with respect to SP-at-entry
// Start by saving these:
// [sp, #-0x40] <== x26; x27
// [sp, #-0x30] <== x28; x29
stp x26, x27, [sp, #-0x40]
stp x28, x29, [sp, #-0x30]
View aarch64_core_dump.cpp
/* Copyright (c) 2005-2007, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
@mcejp
mcejp / serve.sh
Created May 22, 2023 20:51
Jekyll in Podman
View serve.sh
#!/bin/sh
set -ex
podman start -ia jekyll || podman run -it \
--name jekyll \
--volume=$PWD:/srv/jekyll \
--env JEKYLL_ENV=production \
--env JEKYLL_ROOTLESS=1 \
-p 4000:4000 \
docker.io/jekyll/jekyll:4.1.0 \
View make-release.sh
#!/bin/bash
if [[ $# -ne 1 ]] ; then
echo 'usage: make_release.sh RELEASE'
echo ' example: ./make-release.sh 2022.06'
exit 1
fi
set -e
@mcejp
mcejp / line_writer.py
Created May 1, 2023 12:09
Pattern: line writer with indentation
View line_writer.py
class LineWriter:
def __init__(self, f, indent=0):
self._f = f
self._indent = indent
def indented(self) -> "LineSink":
return LineSink(self._f, self._indent + 1)
def write_line(self, s=None):
if s is not None:
@mcejp
mcejp / FileEmbed.cmake
Last active January 26, 2023 10:36
CMake function to convert a binary file into a C++ header embedding the data as std::span<uint8_t>
View FileEmbed.cmake
# Adapted from original:
# https://jonathanhamberg.com/post/cmake-file-embedding/
# https://gitlab.com/jhamberg/cmake-examples/-/blob/master/cmake/FileEmbed.cmake
function(FileEmbed_Add input output c_name)
add_custom_command(
OUTPUT ${output}
COMMAND ${CMAKE_COMMAND}
-DRUN_FILE_EMBED_GENERATE=1
-DINPUT_FILE=${input}
View fast-median.rkt
#lang racket
(provide fast-median)
(define (median-of-5 vec)
(when (> (vector-length vec) 5) (error "median-of-5 shall be only used for short vectors"))
(define n (vector-length vec))
(vector-ref (vector-sort vec <) (floor (/ n 2))))
@mcejp
mcejp / VGASimulator.py
Created May 9, 2022 22:03 — forked from pvieito/VGASimulator.py
Simulate and view VGA output from a VHDL simulation
View VGASimulator.py
#!/usr/bin/env python3
'''VGASimulator.py - Pedro José Pereira Vieito © 2016
View VGA output from a VHDL simulation.
Ported from VGA Simulator:
https://github.com/MadLittleMods/vga-simulator
by Eric Eastwood <contact@ericeastwood.com>
More info about how to generate VGA output from VHDL simulation here:
http://ericeastwood.com/blog/8/vga-simulator-getting-started