Skip to content

Instantly share code, notes, and snippets.

View GeorgeDewar's full-sized avatar

George Dewar GeorgeDewar

  • Wellington, New Zealand
View GitHub Profile
@GeorgeDewar
GeorgeDewar / do-node
Last active August 29, 2015 13:56
Handy little script to shut down or boot up droplets on Digital Ocean - great for demonstrating redundant systems like Ceph, where similarly named nodes need to be killed and restarted during demonstrations.
#!/bin/bash
function usage {
echo "Shutdown and boot Digital Ocean droplets remotely, and simulate network disconnection"
echo
echo "Usage: $0 <kill/boot/killnet/resumenet> node1 [node2] [node3] [node...]"
exit 1
}
# Get settings and node IDs from files
@GeorgeDewar
GeorgeDewar / killnet
Last active August 29, 2015 13:56
Simulates network disconnection over SSH by dropping all traffic to/from any host other than the host calling the script
#!/bin/bash
#Determine IP of calling user
ssh_ip=`echo $SSH_CLIENT | awk '{ print $1}'`
if [ "$1" == "kill" ]; then
echo "Simulating network disconnection by dropping traffic from all hosts except $ssh_ip..."
#Default Policy to DROP all incoming traffic
@GeorgeDewar
GeorgeDewar / vpn
Last active October 2, 2016 20:13
#!/bin/bash
red='\e[0;31m'
green='\e[0;32m'
NC='\e[0m'
set -e
function usage {
echo Enable/Disable routing all traffic through VPN, and
@GeorgeDewar
GeorgeDewar / sydi2md
Last active August 29, 2015 13:57
Ruby script for converting SYDI XML files to readable Markdown
#!/usr/bin/env ruby
require 'xmlsimple'
require 'pp'
# Table widths will be padded in multiples of 10, so that small increases in maximum length will not always
# modify every line of the table (by increasing the width of the column)
PAD_MULTIPLE=10
# Map one or more hashes to strings within a table row by composing a string from the values in the hash. Fields
#!/usr/bin/ruby
require 'json'
require 'term/ansicolor'
require 'optparse'
require 'httparty'
require 'set'
include Term::ANSIColor
@GeorgeDewar
GeorgeDewar / gist:11171561
Created April 22, 2014 09:21
Checksum calculation example for IR codes of a Fujitsu heat pump (remote AR-RAH1E)
# Sample data
data = []
data[0] = '00101000110001100000000000001000 00001000011111111001000000001100 00001101100000001000000000000000 00000000000000000000010001111111'
data[1] = '00101000110001100000000000001000 00001000011111111001000000001100 00000011100000001000000000000000 00000000000000000000010001110111'
data[2] = '00101000110001100000000000001000 00001000011111111001000000001100 00001101100011001000000000000000 00001011111110010000010011111010'
data[3] = '00101000110001100000000000001000 00001000011111111001000000001100 00001101100000001000100000000000 00000000000000000000010001110111'
data[4] = '00101000110001100000000000001000 00001000011111111001000000001100 00001101000000000000100000000000 00000000000000000000010000001111'
# Checksum function
#!/bin/bash
function usage {
echo Enable or disable CNTLM proxy settings in the current terminal
echo
echo Usage:
echo
echo "source proxy <on / off>"
}
/*
* IRrecord: record and play back IR signals as a minimal
* An IR detector/demodulator must be connected to the input RECV_PIN.
* An IR LED must be connected to the output PWM pin 3.
* A button must be connected to the input BUTTON_PIN; this is the
* send button.
* A visible LED can be connected to STATUS_PIN to provide status.
*
* The logic is:
* If the button is pressed, send the IR code.
@GeorgeDewar
GeorgeDewar / ng
Last active August 29, 2015 14:00
Enable and disable nginx sites
#!/bin/bash
function usage {
echo "Manage nginx sites"
echo
echo "Usage:"
echo
echo "ng pull"
echo "ng push"
echo "ng list"
@GeorgeDewar
GeorgeDewar / es-centos
Last active August 29, 2015 14:00
Install ElasticSearch on CentOS 6.4
#!/bin/bash
yum install -y java-1.7.0-openjdk
cat > /etc/yum.repos.d/ElasticSearch-1.0.repo <<- EOF
[elasticsearch-1.0]
name=Elasticsearch repository for 1.0.x packages
baseurl=http://packages.elasticsearch.org/elasticsearch/1.0/centos
gpgcheck=1
gpgkey=http://packages.elasticsearch.org/GPG-KEY-elasticsearch