Skip to content

Instantly share code, notes, and snippets.

@dansimau
dansimau / send-grafana-cloud-metric.sh
Created May 16, 2022 09:14
Push metric to a Grafana Cloud Graphite instance
#!/bin/bash
set -euo pipefail
api_key="" # API key from Grafana Cloud
metrics_user="" # Graphite username from Grafana Cloud console
metrics_endpoint="" # Graphite endpoint from Grafana Cloud console
now=$(date +%s)
@dansimau
dansimau / spfincludelookup.sh
Last active April 28, 2022 08:44
Recursively return all SPF includes for a given domain
spfincludelookup() { for entry in $(dig +short TXT "$@" |grep --color=never spf); do [ "${entry:0:7}" == "include" -o "${entry:0:6}" == "exists" ] && echo $entry && spfincludelookup ${entry:8}; done; }
spfincludelookup "$@"
#
# Filter input to remove content matching regexp, then output to stdout.
#
# Example:
# cat data.sql | python3 re-filter.py "CREATE TRIGGER.*?;"
#
import re
import sys
matcher = re.compile(sys.argv[1], re.MULTILINE | re.DOTALL | re.IGNORECASE)
@dansimau
dansimau / README.md
Created July 13, 2012 10:39
Enable git-style colour output in regular diff on Mac OS X

Enable git-style colour output in regular diff

Mac OS X

  1. Install colordiff using Homebrew:

     brew install colordiff
    
  2. Add function to your ~/.bash_profile:

@dansimau
dansimau / benchmark.sh
Created October 13, 2011 12:52
Takes a list of URLs from a file, curls them and saves the load times to a CSV file
#!/bin/bash
FILE=$1
NUM=$2
[ "$3" == "-v" ] && VERBOSE=1
usage() {
echo "Usage: $0 <file of URLs> <number of requests to do per URL> [-v]" >&2
}
@dansimau
dansimau / RunParallel.go
Created November 20, 2016 04:11
RunParallel is a drop-in replacement for testify/suite.Run that runs all tests in parallel.
// RunParallel is a drop-in replacement for testify/suite.Run that runs
// all tests in parallel.
//
// It uses reflection to create a new instance of the suite for each
// test
func RunParallel(t *testing.T, userSuite suite.TestingSuite) {
if _, ok := userSuite.(suite.SetupAllSuite); ok {
t.Log("Warning: SetupSuite exists but not being run in parallel mode.")
}
if _, ok := userSuite.(suite.TearDownAllSuite); ok {
@dansimau
dansimau / pgprepmgr.sh
Created January 9, 2012 10:57
Wrapper for pgpools' pcp tools to help you manage your pgpool setup and postgresql cluster. See usage in the comment below.
#!/bin/bash
#
# pgpool-II replication manager
#
# Interfaces with pgpool's pcp command-line tools to provide access to common functions for managing
# load-balancing and failover.
#
# dsimmons@squiz.co.uk
# 2011-08-28
@dansimau
dansimau / revert-lights-out.py
Created January 3, 2015 12:27
Undo a Mac theme stuck in dark mode due to https://github.com/samturner/lights-out
from Foundation import CFPreferencesSetValue
from Foundation import CFNotificationCenterPostNotification
from Foundation import CFNotificationCenterGetDistributedCenter
from Foundation import kCFPreferencesAnyApplication
from Foundation import kCFPreferencesCurrentUser
from Foundation import kCFPreferencesCurrentHost
# Remove offending preference
CFPreferencesSetValue('AppleInterfaceStyle', None, kCFPreferencesAnyApplication,
kCFPreferencesCurrentUser, kCFPreferencesCurrentHost)
@dansimau
dansimau / git-fetch-reminder.sh
Last active March 31, 2020 11:48
Prints a reminder if you haven't fetched from a git repo for some period of time
#!/bin/bash
#
# Print a reminder if a fetch has not been done in n hours.
#
# There are multiple ways you could invoke this; for example, to have it run
# whenever you change directory you could do:
#
# cd() { command cd "$@"; ~/bin/git-fetch-reminder.sh 2>/dev/null; }
#
@dansimau
dansimau / .gitignore
Created May 20, 2012 23:52 — forked from urschrei/mkflask.sh
Bootstrap a Flask project on Ubuntu Precise, with Puppet, Vagrant and Fabric. (For latest version, see https://github.com/dansimau/flask-bootstrap)
*~
*.pyc
.vagrant
venv