Skip to content

Instantly share code, notes, and snippets.

@hjst
hjst / dell-monitor-vga1-config.sh
Created May 10, 2016 12:09
Configure my Dell monitor (EDID not auto-recognised) via VGA manually with xrandr
#!/bin/sh
# This cvt command calculates the modeline for a 1920×1080 display @ 60Hz
modeline=`cvt 1920 1080 60 | tail -n 1 | cut -d ' ' -f 2-`
modeline_name=`echo ${modeline} | cut -d '"' -f 2`
if xrandr | grep ${modeline_name} > /dev/null; then
# Mode already exists (probably didn't reboot yet) so don't add it
echo "Monitor already configured, skipping..."
else
echo "Adding monitor config modeline from cvt output..."
@hjst
hjst / pinniped.xml
Created December 13, 2016 18:20
Example of XDXF-formatted OED data
<k>pinniped</k><br>
<b>pinniped, <abr>a.</abr> <i>and</i> <abr>n.</abr></b>
<i><abr>Zool.</abr></i><br>
<blockquote>
<blockquote>(<c c="darkslategray">ˈpɪnɪpɛd</c>)</blockquote>
</blockquote><br>
<blockquote>
<blockquote>Also <b>pinnipede</b>, <b>pinnaped</b>.</blockquote>
</blockquote><br>
<blockquote>
@hjst
hjst / abbreviations.tsv
Created December 14, 2016 12:33
Tab-delimited file of abbreviations used in the OED.
abbr title
a. adjective
a. adoption of, adopted from
a (in dates) ante
abbrev. abbreviation (of)
Aberd. Aberdeen
abl. ablative
absol. absolute(ly)
abstr. abstract
Acad. academia, academy, academic(al)
@hjst
hjst / vob-to-mp4.sh
Last active April 21, 2017 15:16
Reencode .VOB files from an old DVD to .mp4 files of reasonable size
# Based on the two-pass suggestions here: https://trac.ffmpeg.org/wiki/Encode/H.264
#
# Optional: for multiple VOB files you wish to concatenate, do so *before* reencoding:
ffmpeg -i "concat:VTS_01_1.VOB|VTS_01_2.VOB|VTS_01_3.VOB" -c copy CONCAT.VOB
# The target average bitrate (for -b:v switch) is calculated like so:
# For a video that's 600 seconds long and a target filesize of 200MB
# (200 MiB * 8192 [converts MiB to kBit]) / 600 seconds = ~2730 kBit/s total bitrate
# 2730 - 128 kBit/s (desired audio bitrate) = 2602 kBit/s video bitrate
@hjst
hjst / 1_query.graphql
Last active May 11, 2017 10:02
Sample cross-table query with postgraphql 3.2.0
{
allFilms(first: 5) {
edges {
cursor
node {
nodeId
filmId
title
releaseYear
actors: filmActorsByFilmId {
@hjst
hjst / aws_set_mfa_env_vars.sh
Created June 2, 2017 13:30
Shell function to set temporary MFA session env vars for AWS CLI access
aws_set_mfa_env_vars () {
# This assumes you have the aws-cli tool already set up and working:
# http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html
#
# This is the ARN for your MFA device, it's found in the "Security
# Credentials" tab of your IAM user summary
mfa_arn="arn:aws:iam::01234567890:mfa/your.name.here"
# This function only takes one parameter: the current TOTP value
# shown on your MFA device (will be a 6 digit number)
@hjst
hjst / url-version-finder.sh
Created July 7, 2017 17:08
Try to find valid downloads for files with a version number in their URL
curl --head --silent --output /dev/null \
--write-out "%{http_code}: %{url_effective}\n" \
https://s3.amazonaws.com/bucket/foo/bar-2.[6-82].[0-9]-[1-9].baz.[0-9].tgz \
| grep -v ^403
# --head # do a HEAD, not a GET; understand the tradeoffs
# --silent # hush the usual output progress bars etc.
# --output /dev/null # hush the remaining output (header echoes)
# --write-out "%{http_code}: %{url_effective}\n" # output these specific fields on a line, suitable for grep
# .../bucket/foo/bar-2.[6-82].[0-9]-[1-9].baz.[0-9].tgz # URL pattern, usual bash syntax
@hjst
hjst / send-to-pocket.el
Created August 28, 2017 14:27
ELisp function to send the URL under the cursor to Pocket for reading later (uses msmtp)
(require 'url-util)
(defun hjst/send-to-pocket ()
"Send the URL at point to Pocket for reading later"
(interactive)
(let
((url (url-get-url-at-point)))
(start-process-shell-command "msmtp" "*send-to-pocket*"
(concat "printf 'Add:\n%s\n'"
url
"| msmtp add@getpocket.com"))
@hjst
hjst / gist:1326755
Last active November 21, 2018 05:22
Format a javascript Date object as a 12h am/pm time string.
function format_time(date_obj) {
// formats a javascript Date object into a 12h AM/PM time string
var hour = date_obj.getHours();
var minute = date_obj.getMinutes();
var amPM = (hour > 11) ? "pm" : "am";
if(hour > 12) {
hour -= 12;
} else if(hour == 0) {
hour = "12";
}
@hjst
hjst / [Radio Streams].m3u
Created October 28, 2018 13:02
MPD playlist file for BBC radio streams at /var/lib/mpd/playlists/[Radio Streams].m3u
http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/llnw/bbc_radio_hereford_worcester.m3u8#BBC Hereford & Worcester
http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/llnw/bbc_radio_one.m3u8#BBC Radio 1
http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/llnw/bbc_1xtra.m3u8#BBC Radio 1Xtra
http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/llnw/bbc_radio_two.m3u8#BBC Radio 2
http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/llnw/bbc_radio_three.m3u8#BBC Radio 3
http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/nonuk/sbr_low/llnw/bbc_radio_fourfm.m3u8#BBC Radio 4
http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/nonuk/sbr_low/llnw/bbc_radio_five_live.m3u8#BBC Radio 5 Live
http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_low/llnw/bbc_radio_five_live_sports_extra.m3u8#BBC Radio 5 Live Sports Extra
http://a.files.bbci.