Skip to content

Instantly share code, notes, and snippets.

@dansimau
dansimau / bash-processor.sh
Created February 24, 2011 16:31
A bash script/template for adding multi-processing to something (ie. another script)
#!/bin/bash
#
# A bash script/template for adding multi-processing to "stuff".
#
# Designed to be used for syncing files though. Takes "strings of stuff" (eg.
# filenames) into a queue, flattens duplicates, then spawns a worker after a
# few seconds that calls the processing script with the "stuff" as params.
#
# dsimmons@squiz.co.uk
# 2011-02-24

Keybase proof

I hereby claim:

  • I am dansimau on github.
  • I am dansimau (https://keybase.io/dansimau) on keybase.
  • I have a public key ASBxOKX07kpA124KgQBfA2hD23-v7xTfi0EdIv45ePiv8wo

To claim this, I am signing this object:

@dansimau
dansimau / git-unmerged.py
Last active April 22, 2019 04:52
Report branches or commits that are not yet merged into master.
#!/usr/bin/python
"""
Report branches or commits that are not yet merged into master.
"""
import subprocess
from os.path import basename
# Merge/environment branches. These will be excluded from the
# "unmerged branches" list.
EXCLUDE_BRANCHES = ['staging', 'uat', 'production', 'master']
@dansimau
dansimau / google-maps-takeout-to-kml.py
Created October 18, 2018 08:10
Convert starred places from Google Maps to a KML document (via Google Takeout).
"""
Takes a list of JSON files from Google Takeout's "Maps (Your Places)" and
converts them into KML documents.
"""
import json
import os
import simplekml
import sys
import unicodedata
import xml.sax.saxutils
@dansimau
dansimau / gist:842415
Created February 24, 2011 16:41
Bash function for running a command, checking the return code, and re-trying it x times after y sleep seconds.
#
# "<cmd>" <retry times> <retry wait>
#
do_retry()
{
cmd="$1"
retry_times=$2
retry_wait=$3
c=0
@dansimau
dansimau / go.sh
Last active November 30, 2017 17:02
Bash functions for navigating Go workspaces ("Go-go!")
#
# Change to the directory of the specified Go package name.
#
gg() {
paths=($(g "$@"))
path_index=0
if [ ${#paths[@]} -gt 1 ]; then
c=1
@dansimau
dansimau / pglag.sh
Created January 9, 2012 11:58
Calculate the replication lag between postgresql master and one or more slaves in streaming replication mode.
#!/bin/bash
#
# Show replication lag for one or more postgresql slaves in streaming replication.
#
# dsimmons@squiz.co.uk
# 2012-01-09
#
psql="which psql"
psql_extra_opts=""
@dansimau
dansimau / go-test-pretty.sh
Created April 10, 2017 07:49
Run `go test`, only displaying error output, plus print counts of all tests passed/failed/etc.
#!/bin/bash
#
# Runs `go test -v`, parses the output and only displays errors. Also displays
# a summary of tests passed/failed/skipped/etc.
#
set -o pipefail
declare buffer=
declare test_error=false
@dansimau
dansimau / colourpicker.scpt
Created August 5, 2012 15:40
A colour picker app for Mac OS X
set the RGB16bit_list to (choose color)
-- convert choosen color to HEX
set the formatedColor to my RBG_to_HEX(RGB16bit_list)
set the clipboard to formatedColor
display dialog "HEX colour value (" & formatedColor & ") has been copied to the clipboard." with icon 1 buttons {"Dismiss"} default button {"Dismiss"} giving up after 10
on RBG_to_HEX(RGB_values)
-- this subroutine was taken from "http://www.apple.com/applescript/sbrt/sbrt-04.html"
set the hex_list to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
@dansimau
dansimau / go-get-version.sh
Last active November 14, 2016 17:54
Like `go get`, but specify a commit ref in the package spec
#!/bin/bash
#
# Same as `go get` but you can specify a git commit ref.
#
set -e
#
# Resolve the path to the Go workspace from GOPATH.
#
_go_workspace() {