Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / dell-price-watch.sh
Last active September 8, 2017 19:07
cron script to watch a particular product on Dell.com to go on sale
#!/bin/bash -e
set -o pipefail
json=$(curl -sS --fail "$PRODUCT_URL" |
grep -Po 'Dell.Services.DataModel = .*;' |
awk '{sub("Dell.Services.DataModel = ", "");sub(";$", "");print}' |
jq '.Stacks[0].Stack'
)
name=$(jq -r '.Title.InnerValue' <<<"$json")
@jcttrll
jcttrll / pass-by-reference.sh
Created August 9, 2017 14:05
Pass-by-reference example in Bash
#!/bin/bash -e
set -o pipefail
referrer() {
local -n reference="$1"
echo "In referrer: ${!reference}"
reference=reassigned
}
@jcttrll
jcttrll / twitter.sh
Last active August 9, 2017 19:12
Quick-'n'-dirty shell script to hit the Twitter REST APIs
#!/bin/bash -e
set -o pipefail
fail() {
echo "$*" >&2
return 1
}
verify-utilities-available() {
local util
@jcttrll
jcttrll / Blah.groovy
Created August 8, 2017 14:51
Spock test with data table
@Unroll
"LD X, [M] -> #value.hex32"() {
setup:
Rx3588Processor processor
rom.put(0x00 as byte)
rom.putInt(value as int)
when:
processor = new Rx3588Processor().attachRom(rom.array())
processor.setRegister("M", 1)
@jcttrll
jcttrll / Huffman.java
Last active July 29, 2017 17:38
Simple Huffman coding example for character strings
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import static java.lang.Math.min;
import static java.util.stream.Collectors.counting;
import static java.util.stream.Collectors.groupingBy;
@jcttrll
jcttrll / lamba-storage-calc.sh
Last active July 12, 2017 17:57
Usage: lambda-storage-calc.sh --region <aws-region>
#!/bin/bash -e
if [ $# -ne 2 -o ! "$1" = "--region" ]; then
echo "Usage: ${0##*/} --region <aws-region>" 2>&1
exit 1
fi
AWS_REGION="$2"
AWS_OPTIONS+=" --region $AWS_REGION --output json"
@jcttrll
jcttrll / send-ses.sh
Last active January 18, 2024 23:34
Send an e-mail from the command line using AWS SES SMTP
#!/bin/bash -e
set -o pipefail
# PREREQUISITES:
#
# 1. mailx command line utility
# 2. Firewall access to TLS SMTP port 465 on the SES server specified in SES_ENDPOINT, below.
#
# INSTRUCTIONS:
#
@jcttrll
jcttrll / Dice.java
Created December 27, 2016 04:23
Standalone experimentation with rolling n dice with s sides.
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
public class Dice {
public static void main(String[] args) {
SortedMap<Long, Long> zeroSixSidedDice = sumOccurrencesOfDiceRoll(6, 0);
SortedMap<Long, Long> singleSixSidedDie = sumOccurrencesOfDiceRoll(6, 1);
SortedMap<Long, Long> twoSixSidedDice = sumOccurrencesOfDiceRoll(6, 2);
SortedMap<Long, Long> threeSixSidedDice = sumOccurrencesOfDiceRoll(6, 3);