Skip to content

Instantly share code, notes, and snippets.

# This is Kev's slate file
config defaultToCurrentScreen true
config nudgePercentOf screenSize
config resizePercentOf screenSize
config windowHintsIgnoreHiddenWindows false
config windowHintsShowIcons true
config windowHintsDuration 10
config focusPreferSameApp false
@kbhaines
kbhaines / KeyRemap MacBook swap symbols & numbers
Last active January 9, 2018 20:30
Karabiner Configuration
<?xml version="1.0"?>
<root>
<item>
<name>Remap CapsLock to Hyper</name>
<appendix>OS X doesn't have a Hyper. This maps Left Control to Control + Shift + Option + Command.</appendix>
<identifier>space_cadet.left_control_to_hyper</identifier>
<autogen>
--KeyToKey-- KeyCode::F19, KeyCode::COMMAND_L, ModifierFlag::OPTION_L | ModifierFlag::SHIFT_L | ModifierFlag::CONTROL_L
@kbhaines
kbhaines / Watch
Last active August 29, 2015 14:01
File watch
#!/bin/sh
PREFIX=$1
while [ 1 ];do
for f in $PREFIX*;do
if ! lsof $f >/dev/null;then
echo $f is ready
# do something with it, then rm/mv it out of the way...
...
fi
@kbhaines
kbhaines / BasicAuthFetch
Created August 15, 2014 14:29
Doing URL fetch with Basic authorization from AppEngine
@GET
@Path("/urlfetch/{url}")
public Response urlFetch(@PathParam("url") String userUrl) {
String result = "";
try {
URL url = new URL("https://" + userUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// Header is "Basic <base64 encoded username:password>"
// e.g. echo "kevin:password" | openssl env -base64 will give you this
@kbhaines
kbhaines / PrologExperiments
Created September 16, 2014 10:55
Experiments with Prolog for Constraints Programming
?- use_module(library(clpfd)).
/* type go(200, Answer) to run the program. 200 is the highest side */
/* length it will look for. */
go(Top, [L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11,L12,L13,L14,
L15,L16,L17,L18,L19,L20,L21,L22,L23,L24,L25]) :-
/* Start the timer */
@kbhaines
kbhaines / witch.prolog
Last active August 29, 2015 14:08
Prolog Constraints Programming
?- use_module(library(clpfd)).
/*
Load: ['witch.prolog'].
Run: witch(5,Result).
*/
witch(Top, Vars) :-
Vars = [L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11,L12,L13,L14,
L15,L16,L17,L18,L19,L20,L21,L22,L23,L24,L25],
@kbhaines
kbhaines / backup.sh
Last active September 24, 2016 11:11
Simple backup script, using hard-links and rsync to efficiently backup entire directories
#!/bin/sh
set -e
usage() {
echo "$0 <backup-media> <source-dir> [<source-dir>...]"
echo "where backup-media = directory to backup to"
echo "and source-dir = one or more directories to backup"
}
get_last_id() {
@kbhaines
kbhaines / nord.sh
Created February 11, 2017 15:30
NordVpn connection starter
# Assumes you've installed the nordvpn zip file into /etc/openvpn
#
# To use:
# 1) create a file /etc/openvpn/nordvpn with username on line 1, password on line 2
# 2) source this into your shell
# 3) Run:
# vpn # defaults to a random VPN in the UK
# vpn nl # connects to random VPN in Netherlands
# vpn uk1 # connects to random VPN starting with 'uk1'
@kbhaines
kbhaines / openvpn.sh
Last active March 4, 2017 11:58
OpenVPN config to randomise vpn connections
# Put this at the end of /etc/default/openvpn
AUTOSTART="nordvpn"
prefix=uk[0-9][0-9]
VPN_HOME=/etc/openvpn
target=`ls $VPN_HOME/${prefix}.nordvpn*udp*|shuf -n 1`
VPN_CONF=$VPN_HOME/nordvpn.conf
cp $target $VPN_CONF
sed -i "s/auth-user-pass.*/auth-user-pass \/etc\/openvpn\/nordvpn-auth/" $VPN_CONF
echo "up $VPN_HOME/update-resolv-conf" >> $VPN_CONF
@kbhaines
kbhaines / main.go
Last active October 4, 2017 08:55
GoLang Oauth2 using Google Application Default Credentials
package main
import (
"context"
"fmt"
"log"
"net/http"
"golang.org/x/oauth2/google"
"google.golang.org/api/oauth2/v2"