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 / 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
}, {})
@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 / 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 / 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 / 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 / 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 / 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
#import dialogs, ugfx, network, badge, deepsleep
#import dialogs from micropython/unix/modules/dialogs.py
import ugfx, network, badge, time
mocked_messages = [
'sshow: hei, verden!',
'krav: hello, world!',
'sshow: funker dette?',
'krav: ja :):):):)',
'sshow: hei, verden!',
@stigok
stigok / config.txt
Created September 9, 2017 23:59
Sample Pi boot config
# See /boot/overlays/README for all available options
gpu_mem=128
start_file=start_x.elf
fixup_file=fixup_x.dat
initramfs initramfs-linux.img followkernel
# Enable ALSA interface
audio=on
uart0=off
const int SECOND = 1000;
const int MINUTE = 60 * SECOND;
const int RESOLUTION = 1 * SECOND;
//const int EXTRA_TURN_TIME = SECOND;
const int GREEN = 0;
const int RED = 1;
const int DRY_RUN = 1; // Comment this whole line to enable gpio pins