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 / closet.sh
Last active May 25, 2016 22:34
Bash utility to copy a skeleton directory to predefined target path
#!/bin/bash
# Set $skeleton to desired path and rename the file to e.g. closet.sh
# Set $path to desired target directory to raise the skeleton
# Usage: closet project-name
name=$1
path=~/repos/$name
skeleton=~/repos/sshow-node-module-skeleton
if [ "$1" == "--current" ]; then
@stigok
stigok / whothis.sh
Created May 27, 2016 03:47
Which pacman package supplies this binary
#!/usr/bin/env bash
echo "Who this :) <21"
if [ "$1" = "" ]; then
echo "Missing arg"
exit 1
fi
filepath=$(which $1 2> /dev/null)
@stigok
stigok / ago.js
Last active February 24, 2017 15:32
Lightweight relative time ago in English
const SECOND = 1000
const MINUTE = SECOND * 60
const HOUR = MINUTE * 60
const DAY = HOUR * 24
function timeAgo (date) {
const delta = Date.now() - parseInt(date)
const ago = {
day: delta / DAY,
hour: delta / HOUR,
@stigok
stigok / githook.js
Last active July 30, 2023 09:46
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')
#!/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 / 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 / .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