Skip to content

Instantly share code, notes, and snippets.

View mkasberg's full-sized avatar

Mike Kasberg mkasberg

View GitHub Profile
@mkasberg
mkasberg / csv2json.php
Created January 21, 2017 02:46
Converts a CSV to JSON array based on CSV headings.
#!/usr/bin/env php
<?php
print "CSV 2 JSON\n";
if (!isset($argv[2])) {
print "Usage: csv2json.php infile.csv outfile.json\n";
exit();
}
@mkasberg
mkasberg / CustomLogger.php
Last active April 1, 2018 12:19
PHPUnit Hides Errors After set_error_handler() Called
<?php
class CustomLogger {
public function __construct() {
// Try commenting out this line:
set_error_handler(array($this, 'handleError'));
}
public function __desctruct() {
restore_error_handler();
@mkasberg
mkasberg / loundorm.py
Last active April 29, 2022 07:09 — forked from kylophone/loudness.rb
FFmpeg loudnorm filter - dual pass loudness normalization example - http://k.ylo.ph/2016/04/04/loudnorm.html
#!/usr/bin/env python
import json
import os
from subprocess import check_call, check_output, STDOUT
import sys
if len(sys.argv) != 3:
print "Usage: %s input.wav output.wav" % __file__
sys.exit(1)

Keybase proof

I hereby claim:

  • I am mkasberg on github.
  • I am mkasberg (https://keybase.io/mkasberg) on keybase.
  • I have a public key ASApuEY9bNVN-3fR7rfBoOwjBdVVJpPd9SmtCxCAst4gHQo

To claim this, I am signing this object:

@mkasberg
mkasberg / backup-with-rsync.sh
Last active April 23, 2020 02:49
A simple script to make backups with rsync easy!
#!/usr/bin/env bash
# A simple script to make backups with rsync easy!
# This will backup the entire home dir of the current user.
# (I always forget these commands.)
function print_usage {
cat << EOF
Usage: $0 [options]
@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.
#!/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 / 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."
@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 / 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.
#