Skip to content

Instantly share code, notes, and snippets.

View stigok's full-sized avatar
🚢
ship it!

Stig Otnes Kolstad stigok

🚢
ship it!
View GitHub Profile
@stigok
stigok / after-rsync
Created July 30, 2017 17:22
File system watcher that executes a command when MOVED_TO event occurs, i.e. when rsync file transfer is complete
#!/bin/bash
# Do something after rsync completes
#
# Usage: after-rsync <srcdir> <command> [...args]
set -x
srcdir=$1
shift
@stigok
stigok / vid2html5
Created July 30, 2017 17:18
Convert a video file to a cross-browser HTML5 video compatible file format
#!/bin/bash
# Convert a video file to a cross-browser HTML5 video compatible file format
#
# Usage: vid2html5 <infile> [<outdir>]
#
# stigok jul 2017
infile="$1"
timestamp=`date +'%Y-%m-%d-%H%M%S'`
outdir=${2:-.}
outfile=$outdir/$timestamp.mp4
@stigok
stigok / openvpn-reconnect.sh
Created July 13, 2017 11:41
Make openvpn reconnect when a network interface goes up
#!/bin/bash
# Initiates reconnect of the openvpn process
#
# Made for /etc/NetworkManager/dispatcher.d/, but should be working
# for /etc/network/if-up.d/ as well.
#
IFACE=$1
ACTION=$2
@stigok
stigok / .Xmodmap
Last active April 15, 2022 18:36
Norwegian characters on US keyboard layout with Caps Lock as modifier key (.Xmodmap). See comments for usage instructions.
clear lock
!Maps Caps-Lock as Level3 Shift
keycode 66 = Mode_switch ISO_Level3_Shift
!Norwegian alpha chars ÆØÅ
keycode 47 = semicolon colon oslash Oslash
keycode 48 = apostrophe quotedbl ae AE
keycode 34 = bracketleft braceleft aring Aring
@stigok
stigok / ip6tables-rules
Last active July 4, 2017 08:54
ip6tables restore script for /etc/network/if-up.d
#!/bin/bash
#
# Restores ip6tables configuration.
# Expected to reject everything BUT:
# - icmpv6 from anywhere
# - ssh (22/tcp) from a whitelisted ipv6 subnet
# - openvpn (1094/udp) from anywhere
#
# stigok, july 2017
@stigok
stigok / gogs-issue
Last active June 12, 2017 12:12
Create new issue in git repository on Gogs server instance
#!/bin/bash
# Create an issue on a Gogs repo specified by pwd's git remote
# Exit codes:
# 1 : Missing env
# 2 : Curl error
# 3 : JSON parsing error
# Get a key at https://<gogs-server-url>/user/settings/applications
api_server="$GOGS_SERVER_URL"
api_key="$GOGS_SERVER_API_KEY"
@stigok
stigok / jsonprop
Created June 11, 2017 23:13
Return value of property with specified key in JSON object read from stdin
#!/usr/bin/env node
const args = process.argv.slice(2)
const key = args[0]
if (!key) {
console.error('Missing argument')
process.exit(1)
}
let buffer = ''
@stigok
stigok / datestrings.js
Last active June 4, 2017 23:30
Norwegian date and time strings with leading zero
function datestrings (date) {
const format = ['year', 'month', 'day', 'hour', 'minute', 'second']
const parts = date
.toISOString()
.split(/[^\d]/g)
.slice(0, format.length)
.reduce((obj, part, i) => {
obj[format[i]] = part
return obj
}, {})
#!/bin/bash
# made for tghack '17
# desc: upload a file chunked through a shell with length
# restrictions of commands. you might need to manually
# tune the BUFLEN to stay within the limits. sh syntax
# errors appears when you're out of bounds.
#
# todo: progress bar
#
HOST=${1}
@stigok
stigok / githook.js
Last active August 8, 2025 08:55
Verify GitHub webhook signature header in Node.js
/*
* Verify GitHub webhook signature header in Node.js
* Written by stigok and others (see gist link for contributor comments)
* https://gist.github.com/stigok/57d075c1cf2a609cb758898c0b202428
* Licensed CC0 1.0 Universal
*/
const crypto = require('crypto')
const express = require('express')
const bodyParser = require('body-parser')