Skip to content

Instantly share code, notes, and snippets.

View mkasberg's full-sized avatar

Mike Kasberg mkasberg

View GitHub Profile
@mkasberg
mkasberg / find_broken_links.rb
Created December 20, 2023 18:29
A Ruby script to find broken links
@mkasberg
mkasberg / ParseJson.java
Created September 7, 2023 00:34
Boilerplate to parse JSON in Java
/**
* Download the latest json-java.jar from https://github.com/stleary/JSON-java#readme
* Place it in the same folder as this file
*
* Compile (Windows): javac -cp .;json-java.jar ParseJson.java
* Compile (Unix): javac -cp .:json-java.jar ParseJson.java
*
* Run (Windows): java -cp .;json-java.jar ParseJson FILENAME.json
* Run (Unix): java -cp .:json-java.jar ParseJson FILENAME.json
*/
@mkasberg
mkasberg / parse_json.py
Created September 7, 2023 00:32
Boilerplate to parse JSON in Python
#!/usr/bin/env python3
import sys
import json
if len(sys.argv) < 2:
print("Usage: parse_json.py FILENAME.json")
exit(1)
filename = sys.argv[1]
@mkasberg
mkasberg / parse_json.js
Created September 7, 2023 00:31
Boilerplate to parse JSON in Javascript
#!/usr/bin/env node
const fs = require('fs');
const filename = process.argv[2];
if (filename == null) {
console.log("Usage: parse_json.js FILENAME.json")
process.exit(1);
}
@mkasberg
mkasberg / parse_json.rb
Created September 7, 2023 00:30
Boilerplate to parse a JSON file in Ruby
#!/usr/bin/env ruby
require 'json'
if ARGV[0].nil?
puts 'Usage: parse_json.rb FILENAME.json'
exit 1
end
data = JSON.load_file(ARGV[0], symbolize_names: true)
@mkasberg
mkasberg / commit-message-ratio.rb
Created August 31, 2022 02:22
Commit Message Ratio - a made up ratio defined as the ratio of the number of words in the message body to the lines of code changed
#!/usr/bin/env ruby
# Define the "commit message ratio" as (commit_body_words / commit_lines_changed).
#
# With no args, this script will find the commit message ratio of all commits in
# the git repo in the pwd, and will sort them by that ratio.
# (Commits with a high commit message ratio tend to be interesting commits!)
#
# With a commit hash as the only arg, provide the commit message ratio of that commit.
#
@mkasberg
mkasberg / loudnorm.rb
Created April 9, 2022 19:43
FFmpeg loudnorm filter - dual pass loudness normalization example - http://k.ylo.ph/2016/04/04/loudnorm.html
#!/usr/bin/env ruby
require 'optparse'
require 'json'
metadata = {}
TARGET_I = "-16"
TARGET_TP = "-1.5"
TARGET_LRA = "11"
SAMPLE_RATE = "44100"
BITRATE = "128k"
@mkasberg
mkasberg / Makefile
Created February 6, 2022 17:07
A Makefile for building Docker images - customize to suit your needs
.PHONY: help image test shell clean
DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
help:
@echo "Usage: make [target]"
@echo ""
@echo "Targets:"
@echo " help Print this help message."
@echo " image Build the my-project:latest Docker image."
@echo " shell Open a shell inside the Docker container."
#!/usr/bin/env bash
# Keep this script in a directory with the master copy of your dotfiles.
# For example, keep this script in a dotfiles folder in your Dropbox.
# Run this script to diff your dotfiles between the master copy (in the pwd)
# and the dotfiles installed at ~.
show_help() {
cat <<EOF
Usage: diff-dotfiles.sh OPTION [filename]
@mkasberg
mkasberg / date_shift.rb
Created July 7, 2020 22:30
Shift dates uniformly in any XML file
#!/usr/bin/env ruby
require 'time'
usage = """
Usage: date_shift.rb SECONDS FILE
Look for dates like 2020-06-01T12:26:41Z in FILE
and shift all of them by SECONDS. Print the result to
STDOUT.