Skip to content

Instantly share code, notes, and snippets.

@jcttrll
jcttrll / ocr-rename.sh
Created August 30, 2017 17:35
Quick-'n'-dirty rename of scanned PDFs based on OCR of content (requires Tesseract, ImageMagick)
#/bin/bash -e
set -o pipefail
REGION_X=1920
REGION_Y=2210
REGION_WIDTH=320
REGION_HEIGHT=100
RENAME_PATTERN='foo-%s.pdf'
for file in "$@"; do
@jcttrll
jcttrll / initrd-mod-abort.sh
Created September 27, 2017 17:53
initrd-mod scripts for opennSUSE (and possibly RedHat)
#!/bin/bash -e
set -o pipefail
if [ $# -ne 0 ]; then
echo "Usage: ${0##*/}" >&2
exit 1
fi
EARLY_CPIO_DIR=.initrd-mod-early-cpio
ARCHIVE_DIR=.initrd-mod-archive
@jcttrll
jcttrll / build.sh
Last active November 30, 2017 19:05
C mocking experiment
gcc -c main.c -o main.o
gcc -c framework.c -o framework.o
gcc -c test.c -o test.o
gcc -c mock.c -o mock.o && ar rcs mock.a mock.o; rm mock.o
ld custom.ld test.o main.o framework.o \
-L. --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker \
/lib64/ld-linux-x86-64.so.2 \
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../lib64/crt1.o \
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../lib64/crti.o \
@jcttrll
jcttrll / SimpleTest.groovy
Created March 14, 2018 22:56
Demo of Antlr grammar testing
package com.perihelios.parser.javaregex
import com.perihelios.parser.javaregex.helper.TreeMatcher
import org.junit.Assert
import org.junit.Test
class SimpleTests {
private TreeMatcher treeMatcher = new TreeMatcher(JavaRegexLexer, JavaRegexParser, "regex")
@Test
@jcttrll
jcttrll / blah.wast
Created July 3, 2018 12:42
Trivial example of running assembled WebAssembly text in Node
(module
(func $add (param $a i32) (param $b i32) (result i32)
get_local $a
get_local $b
i32.add
)
(export "add" (func $add))
)
@jcttrll
jcttrll / winkey.sh
Created November 10, 2018 15:49
Show Windows product key embedded in ACPI (for use in VMs)
sudo tail -c 29 /sys/firmware/acpi/tables/MSDM && echo
@jcttrll
jcttrll / power-delete.psm1
Last active March 6, 2022 17:02
PowerShell module to take ownership of a file/directory, assign permissions allowing deletion, and then delete the item (recursively in the case of directories, and optionally including deletion of all hardlinks to files)
function Power-Delete {
[CmdletBinding()]
param(
[parameter(Position = 0, ValueFromRemainingArguments = $true, ValueFromPipelineByPropertyName = $true)]
$FullName,
[switch]
$AllHardLinks
)
process {
@jcttrll
jcttrll / SimpleIoTest.java
Created February 4, 2019 04:04
Quick 'n' dirty write performance test
import java.io.*;
import java.util.*;
import java.security.SecureRandom;
public class SimpleIoTest {
private static final int BLOCK_SIZE = 1024 * 1024;
private static final int TOTAL_SIZE = 1024 * 1024 * 1024;
private static final int SEQUENTIAL_ITERATIONS = 32;
private static final int RANDOM_ITERATIONS = 16;
@jcttrll
jcttrll / WaitSpinLocksExample.java
Created January 3, 2020 02:28
Java wait()/notify() example showing and explaining the use of a spinlock around the wait() call
public class WaitSpinLocksExample {
public static void main(String[] args) {
Thread thread1, thread2;
Base bad = new BadImplementationSubjectToSpuriousWakeup();
thread1 = new Thread(bad::print);
thread2 = new Thread(bad::calculate);
thread1.start();
thread2.start();
@jcttrll
jcttrll / error-handler-snippet.sh
Created February 29, 2020 13:22
Bash error handler, with stacktrace with clickable file:line links (in IntelliJ)
trap onError ERR
onError() {
local exitCode=$? command=(${BASH_COMMAND})
if [[ ${BASH_SUBSHELL} -gt 0 ]]; then
exit ${exitCode}
fi
echo -e "\nERROR: Failed with exit code $exitCode when executing: ${command[@]}" >&2