Skip to content

Instantly share code, notes, and snippets.

@cpaulbond
cpaulbond / aws.md
Created August 16, 2017 23:52 — forked from colinvh/aws.md
AWS Region Names

Alternative naming schemes for AWS regions

Purpose

The intent is to define terse, standards-supported names for AWS regions.

Schemes

@cpaulbond
cpaulbond / base-name
Created June 15, 2016 15:25
Strip all the path from a variable in bash.
#!/bin/sh
#>> Strip all the path from a variable in bash.
echo ${0##*/}
@cpaulbond
cpaulbond / dir-name
Created June 15, 2016 15:24
Different ways to get the directory of the script.
#!/bin/sh
#>> Different ways to get the directory of the script.
echo ${0%/*}
echo $(cd ${0%/*} && pwd)
if [[ ${0%/*} = "." ]]
then echo $PWD
else echo ${0%/*}
@cpaulbond
cpaulbond / better-scripts
Last active October 7, 2016 14:38
Options that are sometimes useful in bash.
#!/bin/bash
#> Options that are sometimes useful in bash.
set -o nounset
set -o errexit
set -o pipefail
trap "exit" SIGINT SIGTERM
trap "echo done" EXIT
@cpaulbond
cpaulbond / etcd-dump
Created May 7, 2016 16:47
Dump all etcd key/values under <path> as json. All values are converted to json if possible.
#!/usr/bin/env python3
#>> Dump all etcd key/values under <path> as json. All values are converted to json if possible.
# Example:
# $ etcdctl set /config/a 'String for a'
# String for a
# $ etcdctl set /config/b true
# true
# $ etcdctl set /config/c 100
# 100
# $ etcdctl set /config/d '{"d1":1,"d2":2}'
@cpaulbond
cpaulbond / punt-comments.el
Created February 24, 2016 21:01
Because sometimes the comments are so bad, they just have to go!
(defun punt-comments ()
(interactive)
(goto-char (point-min))
(while (re-search-forward "/\\*\\|//" nil t)
(let ((start (match-beginning 0)))
(if (string= (match-string 0) "/*")
(if (search-forward "*/" nil t)
(delete-region start (point)))
(delete-region start (line-end-position))))))
@cpaulbond
cpaulbond / gostack.el
Last active January 27, 2016 16:30
elisp: Find a filename in a go stack and convert it over to my local environment.
(global-set-key [f9 ?s] 'gostack-goto)
(defun gostack-file ()
(save-excursion
(save-restriction
(end-of-line)
(let ((eol (point)))
(beginning-of-line)
(narrow-to-region (point) eol)