Skip to content

Instantly share code, notes, and snippets.

View sevaine's full-sized avatar

Andrew Johnson sevaine

  • Octopus Energy P/L
  • Melbourne, AU
View GitHub Profile
@sevaine
sevaine / gist:c6e34482332f364f7e39d7254316dafb
Created June 28, 2017 04:02
insert multi-line string before or after match with sed
# insert before match
sed -i '/PATTERN/ s|^|LINE1\nLINE2\nLINE3\n|' FILE
# insert after match
sed -i '/PATTERN/ s|$|\nLINE1\nLINE2\nLINE3|' FILE
@sevaine
sevaine / update_http_url.sql
Created June 7, 2017 00:28
SQL Select update http url
#
# This should update the url to NEW_IP and NEW_PORT ( UNTESTED )
#
DEFINE NEW_IP = '10.10.10.10'
DEFINE NEW_PORT = '443'
UPDATE DB_NAME.TABLE_NAME
SET field_name=REGEXP_REPLACE(field_name, '(http?://)(.*):(.*)/(.*)', '\1&NEW_IP:&NEW_PORT/\4')
WHERE field_name LIKE 'http%'
AND field_name NOT LIKE '%uri/path%'
@sevaine
sevaine / VMWare-Fusion-OSX-Yosemite-default-VM-Path-change.md
Created September 19, 2015 09:10
Changing the default VM Path in VMWare Fusion on OSX Yosemite

Changing the default VM Path in VMWare Fusion on OSX Yosemite:

I had a little trouble figuring this out - so making a note of it. The VMWare Fusion default location for VMs is ~/Documents/Virtual Machines.localized, which doesnt work well for me as I typically have Documents symbolically linked to my Dropbox directory and prefer to move the default VM location rather than manage exclusions on every Dropbox install I have.

It's relatively straightforward on VMWare Workstation, and Oracle VirtualBox - but for some reason

@sevaine
sevaine / awk-strip-words-and-spaces
Last active June 19, 2017 03:48
remove all letters and numbers, replace space with underscore using awk
cat ${logfile} | awk '/^[A-Za-z0-9]/{gsub("[A-Za-z0-9]", "");gsub(" ","_");print}'
@sevaine
sevaine / exectar-scripts
Created February 27, 2014 01:29
Build executable tarball
### header.sh
#!/bin/sh
AWK=$(which awk 2>/dev/null)
PACKAGES="ruby rubygems git puppet"
TAR_FILENAME="puppetmaster_build.tar.gz"
TMPDIR=$(mktemp -d /tmp/NNNNN)
LINES=$(grep -n '###ENDSCRIPT###' $0 | cut -d':' -f1)
TAR_LINES=$(expr $(wc -l $0) - ${LINES})
tail -n ${TAR_LINES} $0 | cd ${TMPDIR} && tar zxvf -
sudo yum -y install ${PACKAGES}
@sevaine
sevaine / gist:7349048
Created November 7, 2013 04:39
my-small.cnf
# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# You can copy this file to
# /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is /var/lib/mysql) or
@sevaine
sevaine / gist:6136647
Created August 2, 2013 00:40
Raising an exception in ruby when a hash does not contain all required ( expected ) keys
#
# approach 1
#
expected_keys = { :a, :b, :c }
sample_hash = { a: 1, b: 2 }
begin
expected_keys.each { |k| raise StandardError, "#{k} not found" unless sample_hash.has_key? k }
rescue StandardError => e
puts e
end
@sevaine
sevaine / Get-gpg-id-from-email
Created July 26, 2013 05:03
Get a GPG ID, based on an email address
## Local keyring
GPG_ID="$(gpg2 --list-keys --with-colons some.dude@that.domain.com | awk -F':' '/^pub/ { print $5 }')"
## Specified keyring
GPG_ID="$(gpg2 --no-default-keyring --keyring ./some/path/to/keyring.gpg --list-keys --with-colons some.dude@that.domain.com | awk -F':' '/^pub/ { print $5 }')"
@sevaine
sevaine / gist:6076428
Created July 25, 2013 02:26
Stock Bash script with logging / exit function and script name / location enumeration
#!/bin/bash
log() {
local TIMESTAMP="[$(date)]"
if $(echo "${1}" | grep ^WARNING 2>&1 >/dev/null); then
echo "${TIMESTAMP}: $*" 1>&2
elif $(echo "${1}" | grep ^FATAL 2<&1 >/dev/null); then
echo "${TIMESTAMP}: $*" 1>&2
exit 1
else
@sevaine
sevaine / gist:5894324
Created June 30, 2013 08:12
Quick and dirty Python dictionary comprehension of os.listdir to build a dictionary of current dir and file names as keys, and provide their values as the "cleaned" file or dir names. Very handy when bulk renames of files containing spaces, or other non alphanum characters in their name are required.
#!/usr/bin/env python
""" load modules """
import os
import sys
""" What dir are we listing? """
target_dir = sys.argv[1]
""" Build dict """