Skip to content

Instantly share code, notes, and snippets.

View dhensby's full-sized avatar

Daniel Hensby dhensby

  • London, UK
  • 18:14 (UTC +01:00)
  • X @dhensby
View GitHub Profile
@dhensby
dhensby / curl-etag-checker.sh
Created September 6, 2017 22:39
Fetch a resource using curl and use the ETag to check subsequent requests
#!/usr/bin/env bash
ETAG=''
if [ -f /tmp/etag ]; then
ETAG=$(cat /tmp/etag)
fi
head=true
while IFS= read -r line; do
@dhensby
dhensby / MyAuthenticator.php
Created September 1, 2017 10:34
My custom authenticator
<?php
class MyAuthenticator extends MemberAuthenticator {
/**
* Attempt to find and authenticate member if possible from the given data
*
* @param array $data
* @param Form $form
* @param bool &$success Success flag
@dhensby
dhensby / page_controller.php
Created March 15, 2017 21:38
Hiding the show action in silverstripe controller
class Page_Controller extends ContentController {
/**
* An array of actions that can be accessed via a request. Each array element should be an action name, and the
* permissions or conditions required to allow the user to access it.
*
* <code>
* array (
* 'action', // anyone can access this action
* 'action' => true, // same as above
@dhensby
dhensby / dna-test.sh
Last active November 24, 2016 21:56
Pick the "closest" parent branch for a new branch - great for testing pull requests
#!/usr/bin/env bash
function log {
[ ${VERBOSE} ] && echo "$@" >&2
}
VERBOSE=1
if [ -n "$1" ]; then
CURRENT_BRANCH="$1"
else
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
@dhensby
dhensby / ipupdate.sh
Last active June 7, 2020 16:32
Update a hostname in Route53 with your current IP address
#!/usr/bin/env bash
IP=$(curl -s -L https://checkip.amazonaws.com/)
OLDIP=$(cat /tmp/ip)
DOMAIN_REGEX="\s+example\.com"
DOMAIN="sub.example.com"
if [ "${IP}" != "${OLDIP}" ]; then
echo "IP changed from ${OLDIP} to ${IP}"
echo "`date -u +%F-%T` IP changed from ${OLDIP} to ${IP}" >> /tmp/iplog
@dhensby
dhensby / .gitconfig
Last active March 24, 2024 00:14
My standard gitconfig
[user]
name = <name>
email = <email>
signingkey = <GPG key>
[alias]
br = checkout -b
ch = cherry-pick
ci = commit
cim = commit --amend --no-edit
co = checkout
@dhensby
dhensby / silverstripe-deploy.sh
Last active January 13, 2017 21:13
Simple local SilverStripe deploy script for Fedora/CentOS/RHEL
#!/usr/bin/env bash
BU=true
CO=true
BUILD=true
TARGET='master'
DB_USER=''
DB_PASS=''
DB_HOST=''
DB_NAME=''
@dhensby
dhensby / transmission-torrent-rss-shell-parser.sh
Last active May 18, 2016 23:21
Add a torrent to transmission from an RSS feed using bash. Dependency: xmlstarlet
#!/usr/bin/env bash
echo "==== STARTING PARSER ===="
date +'%F %T'
touch /tmp/seen
CURRENT_TIME=$(date +%s)
# assuming we run every 15 mins (900 seconds)
@dhensby
dhensby / swap-on.sh
Last active May 4, 2016 12:31
Enable a swap file for CentOS7 RHEL Fedora
#!/usr/bin/env bash
SWAP_SIZE=1
if [[ $1 =~ ^-?[0-9]+$ ]]; then
SWAP_SIZE="$1"
fi
dd if=/dev/zero of=/swapfile count="$((${SWAP_SIZE} * 1024))" bs=1MiB
chmod 600 /swapfile
@dhensby
dhensby / install-cow.sh
Last active July 23, 2018 10:44
SilverStripe cow installer
#!/usr/bin/env bash
### INSTALL STATE VARS ###
INSTALL_CURL=true
INSTALL_PIP=true
INSTALL_PYTHON=true
INSTALL_AWS=true
INSTALL_TX=true
INSTALL_PHP=true
INSTALL_COMPOSER=true