Skip to content

Instantly share code, notes, and snippets.

Jonathan Cottrill jcttrll

View GitHub Profile
@jcttrll
jcttrll / error-handler-snippet.sh
Created Feb 29, 2020
Bash error handler, with stacktrace with clickable file:line links (in IntelliJ)
View error-handler-snippet.sh
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
@jcttrll
jcttrll / WaitSpinLocksExample.java
Created Jan 3, 2020
Java wait()/notify() example showing and explaining the use of a spinlock around the wait() call
View WaitSpinLocksExample.java
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 / SimpleIoTest.java
Created Feb 4, 2019
Quick 'n' dirty write performance test
View SimpleIoTest.java
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 / power-delete.psm1
Last active Dec 13, 2018
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)
View power-delete.psm1
function Power-Delete {
[CmdletBinding()]
param(
[parameter(Position = 0, ValueFromRemainingArguments = $true, ValueFromPipelineByPropertyName = $true)]
$FullName,
[switch]
$AllHardLinks
)
process {
@jcttrll
jcttrll / winkey.sh
Created Nov 10, 2018
Show Windows product key embedded in ACPI (for use in VMs)
View winkey.sh
sudo tail -c 29 /sys/firmware/acpi/tables/MSDM && echo
@jcttrll
jcttrll / blah.wast
Created Jul 3, 2018
Trivial example of running assembled WebAssembly text in Node
View blah.wast
(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 / SimpleTest.groovy
Created Mar 14, 2018
Demo of Antlr grammar testing
View SimpleTest.groovy
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 / build.sh
Last active Nov 30, 2017
C mocking experiment
View build.sh
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 / initrd-mod-abort.sh
Created Sep 27, 2017
initrd-mod scripts for opennSUSE (and possibly RedHat)
View initrd-mod-abort.sh
#!/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 / ocr-rename.sh
Created Aug 30, 2017
Quick-'n'-dirty rename of scanned PDFs based on OCR of content (requires Tesseract, ImageMagick)
View ocr-rename.sh
#/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
You can’t perform that action at this time.