Skip to content

Instantly share code, notes, and snippets.

@jcttrll
jcttrll / amazon-wishlist-total.js
Created October 13, 2016 05:11
Total prices from Amazon wishlist
// No one knows why Amazon doesn't simply provide a total of item prices for wishlists.
// But with a little script in the F12 Developer Console, you can calculate a total.
Array.from(document.getElementsByClassName("g-item-sortable"))
.map((i) => {
return /\$([0-9.]+)/.exec(i.innerText)[1] - 0
})
.reduce((a,b) => {
return a+b
})
.toLocaleString([], {
@jcttrll
jcttrll / copy-ec2-root-volume.sh
Last active October 20, 2016 22:05
Copies a root (i.e., bootable) EC2 instance volume to a new volume, using rsync to exclude undesirable files
if findmnt -M /mnt >/dev/null 2>&1; then
umount /mnt
fi
DISK_LEADIN_BYTES=$(fdisk -l /dev/xvdb | awk '
/^Device.* Start .* End / {
# Input line will be like:
#
# Device Boot Start End Sectors Size Id Type
#
@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);
@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 / 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 / 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 / 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 / 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 / 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 / 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")