Skip to content

Instantly share code, notes, and snippets.

View z0mbix's full-sized avatar

David Wooldridge z0mbix

View GitHub Profile
@z0mbix
z0mbix / vim-tip.md
Last active February 23, 2017 11:35
  • Run vim without loading ~/.vimrc: vim -u NONE
  • Add quotes around a select word (Requires vim-surround): S"
  • Select entire word no matter where the cursor is: viw
  • Select entire word including trailing space no matter where the cursor is: vaw
  • Enclose entire line in quotes (Needs vim-surround plugin): yss”
  • Comment out paragraph (Requires vim-commentary): gcap
  • Delete quotes around a string: ds"
  • Convert buffers to tabs: :tab ball
  • Close buffer: :bd
  • Uppercase selection: gU
@z0mbix
z0mbix / puppet-custom-fact-role.sh
Created July 7, 2015 15:12
Get an Ec2 instance's role from a tag
#!/usr/bin/env bash
meta_url="http://169.254.169.254/latest/meta-data"
instance_id=$(curl -sf ${meta_url}/instance-id)
role=$(aws ec2 describe-tags --filters \
"Name=resource-type,Values=instance" \
"Name=resource-id,Values=${instance_id}" \
"Name=key,Values=role" \
| jq -r .Tags[].Value)
@z0mbix
z0mbix / ec2-get-instance-tags
Created July 3, 2015 23:39
Bootstrap an EC2 instance with it's role, environment and name
#!/usr/bin/env bash
meta_url="http://169.254.169.254/latest/meta-data"
instance_id=$(curl -sf ${meta_url}/instance-id)
# Get role
aws ec2 describe-tags --filters \
"Name=resource-type,Values=instance" \
"Name=resource-id,Values=${instance_id}" \
"Name=key,Values=role" \
@z0mbix
z0mbix / ssh-ec2
Created July 3, 2015 23:22
SSH to an EC2 instance by name
#!/usr/bin/env bash
#
# SSH to an EC2 instance by name
#
# You need the AWS cli (pip install awscli)
#
if [[ -z $1 ]]; then
echo 'You must specify an instance name!'
exit 1
@z0mbix
z0mbix / tcpdump-es-capture
Created December 19, 2014 14:45
Capture Elasticsearch Queries
# tcpdump -A -nn -s 0 'tcp dst port 9200 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' -i lo
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on lo, link-type EN10MB (Ethernet), capture size 65535 bytes
14:32:33.525122 IP 127.0.0.1.49777 > 127.0.0.1.9200: Flags [P.], seq 313752908:313753888, ack 2465010394, win 257, options [nop,nop,TS val 2684167067 ecr 2684167066], length 980
E...^.@[email protected]#...}L...............
..#...#.GET /index/_search HTTP/1.1
Host: 127.0.0.1:9200
Accept: */*
Content-Length: 845
Content-Type: application/x-www-form-urlencoded
# http://replygif.net/about
# You need jq and rl
if which rl >/dev/null; then
replygif_api_key='39YAprx5Yi'
tags=(pleased approval excited party clapping dance happy)
random_tag=${tags[$RANDOM % ${#tags[@]} ]}
gif=$(curl -s http://replygif.net/api/gifs?api-key=${replygif_api_key}\&tag=${random_tag} | jq .[].file -r | rl -c1)
hipchat_message="(success) -> ${gif}"
fi
@z0mbix
z0mbix / os x syncthing plist howto
Created May 29, 2014 23:07
Example launchd plist for syncthing
Create the XML plist file ~/Library/LaunchAgents/net.syncthing.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>net.syncthing</string>
<key>Program</key>
<string>/Users/zombie/bin/syncthing</string>
### Keybase proof
I hereby claim:
* I am z0mbix on github.
* I am z0mbix (https://keybase.io/z0mbix) on keybase.
* I have a public key whose fingerprint is 310E C49B 374C EE0B 5A53 DB8E FFCE 5C10 5D81 AB88
To claim this, I am signing this object:
@z0mbix
z0mbix / gist:8407613
Last active January 3, 2016 04:18
Packer.io Rackspace UK cloud configuration failure
I have exported SDK_USERNAME, SDK_PASSWORD and SDK_PROVIDER=rackspace-uk
I already use these credentials with other rackspace API tools like pyrax.
$ packer validate staging-web-rackspace.json
Template validated successfully.
$ cat staging-web-rackspace.json
{
"builders":
@z0mbix
z0mbix / install-etcd-centos-6.5
Created January 10, 2014 12:00
Problems installing etcd on centos 6.5
# cat /etc/redhat-release
CentOS release 6.5 (Final)
golang from EPEL:
# rpm -qi golang
Name : golang Relocations: (not relocatable)
Version : 1.1.2 Vendor: Fedora Project
Release : 4.el6 Build Date: Fri 20 Sep 2013 16:21:49 BST
Install Date: Thu 09 Jan 2014 15:14:13 GMT Build Host: buildvm-17.phx2.fedoraproject.org