Skip to content

Instantly share code, notes, and snippets.

@nickrw
nickrw / homecontrol_curtains.go
Last active January 12, 2018 00:01
A curtains HomeKit Accessory hello world using homecontrol https://github.com/brutella/hc
package main
import (
"fmt"
"log"
"sync"
"time"
"github.com/brutella/hc"
"github.com/brutella/hc/accessory"
@nickrw
nickrw / i3lock.sh
Last active March 20, 2019 09:45
i3 screen lock
#!/bin/bash
# depends: scrot imagemagick keychain rivalctl
# Take a screenshot
scrot /tmp/lockshot.png
# Apply pixellation effect
convert /tmp/lockshot.png -scale 5% -scale 2000% /tmp/lockshot-pixel.png
@nickrw
nickrw / elb_dns_log.py
Created April 5, 2017 15:42
ELB DNS logger
#!/usr/bin/env python
# Logs all IP addresses for every ELB in an AWS account
import boto3
import dns.resolver
from dns.exception import DNSException
import logging
logger = logging.getLogger('elbdns')
@nickrw
nickrw / postgres_locks.sql
Created March 10, 2017 10:36
A query for showing the locks in a postgres db
SELECT t.relname, l.locktype, page, virtualtransaction, pid, mode, granted
FROM pg_locks l, pg_stat_all_tables t
WHERE l.relation=t.relid
ORDER BY relation ASC;
@nickrw
nickrw / nextcal.sh
Last active September 7, 2016 16:41
nextcal.sh
#!/bin/sh
# Fetches the next item in your google calendar (assuming pre-set-up by running gcalcli)
CALENDAR_NAME=""
cal="$(gcalcli \
--nostarted \
--calendar $CALENDAR_NAME \
--nocolor \
@nickrw
nickrw / ssh-ec2
Created March 3, 2015 17:04
ssh-ec2 - designed as an alias replacement of ssh. Will try and convert tags or instance IDs to IPs, and opens sessions in tmux if more than one result is returned
#!/bin/bash
try_ec2="$(resolve-ec2 $@)"
if [[ -z $try_ec2 ]]; then
ssh $@
else
if [[ $(echo "$try_ec2" | wc -l ) -gt 1 ]]; then
mux $1 $try_ec2
else
ssh $try_ec2
@nickrw
nickrw / mux
Created March 3, 2015 17:03
mux - takes a session name (optional) and list of hosts - then creates a new tmux session and opens SSH connections to the hosts in split panes
#!/bin/bash
ssh="ssh -o StrictHostKeyChecking=no"
function split_tmux() {
session=$1
shift
count=$(echo $@ | tr ' ' '\n' | wc -l)
echo "Starting session to $count hosts in $session: [$@]"
session="$session ($count)"
@nickrw
nickrw / resolve-ec2
Last active August 29, 2015 14:16
resolve-ec2 - turns command line parameters into IP addresses (Name tags or instance IDs). Intended to be used in conjunction with ssh-ec2 and mux
#!/usr/bin/env python
from boto import ec2
from functools import wraps
import re
def ip4(wrapped_func):
def _dec(request, *args, **kwargs):
response = wrapped_func(request, *args, **kwargs)
return [i.private_ip_address for i in response]
@nickrw
nickrw / spotify-remote.sh
Last active August 26, 2016 15:06
spotify-remote.sh
#!/bin/bash
## My spotify related i3 bindings which use this script
# bindsym XF86AudioPlay exec --no-startup-id ~/bin/spotify-remote.sh playpause
# bindsym XF86AudioStop exec --no-startup-id ~/bin/spotify-remote.sh pause
# bindsym XF86AudioPrev exec --no-startup-id ~/bin/spotify-remote.sh previous
# bindsym XF86AudioNext exec --no-startup-id ~/bin/spotify-remote.sh next
## and other related spotify workspace stuff
# for_window [class="^Spotify"] move to workspace Music

Keybase proof

I hereby claim:

  • I am nickrw on github.
  • I am nickrw (https://keybase.io/nickrw) on keybase.
  • I have a public key whose fingerprint is B4D5 7034 97E0 96A6 EEA8 4CDE DE30 8C8E E20F B087

To claim this, I am signing this object: