Skip to content

Instantly share code, notes, and snippets.

View andycochrane's full-sized avatar

Andy Cochrane andycochrane

View GitHub Profile
dotfiles=$(find ~/dotfiles/* -type f)
for f in $dotfiles; do
. "$f"
done
@andycochrane
andycochrane / snippets.cson
Created March 2, 2017 16:46
Atom auto rel="noopener"
##
# Are you looking for a front-end developer? I’m looking for a new role!
#
# andycdev@gmail.com
# andycochrane.co.uk
##
'*.html':
'Target Blank (with rel="noopener")':
'prefix': 'blank'
@andycochrane
andycochrane / create-s3-website.sh
Last active September 17, 2017 14:36
Create a new s3 bucket and configure it to host a static website using the aws cli. (creates a JSON file in same directory)
#!/bin/sh
# Check for bucket name argument
if [ ! -z "$1" ]; then
# Assign first argument to BUCKET variable
BUCKET=$1;
# Assign second argument to REGION variable or fallback to EU (Ireland) region if not provided.
REGION=${2:-"eu-west-1"}
@andycochrane
andycochrane / .gitconfig
Last active January 6, 2020 08:47
Compare 2 branches by number of commits behind/ahead metric
[alias]
ba = "!f() { \
LEFT=${1-master}; \
RIGHT=${2-HEAD}; \
OUTPUT=$(echo $(git rev-list --left-right --count $LEFT...$RIGHT) "$LEFT $RIGHT" | awk '{print $4\" is \"$1\" behind and \"$2\" ahead of \"$3}');\
echo $OUTPUT; \
}; f"
# Example:
# $ git ba develop feature/shiny-new-feature
@andycochrane
andycochrane / html.json
Created December 15, 2017 17:04
VS Code auto rel="noopener"
"No Opener": {
"prefix": "blank",
"body": [
"target=\"_blank\" rel=\"noopener\""
],
"description": "Add rel=noopener to links with target=_blank"
}
@andycochrane
andycochrane / .gitconfig
Created February 22, 2018 14:40
Alias for setting the upstream of a branch
[alias]
upstream = "!f() { \
REMOTE=${1-origin}; \
OUTPUT=$(echo $(git push -u $REMOTE $(git rev-parse --abbrev-ref HEAD))); \
echo $OUTPUT; \
}; f"
@andycochrane
andycochrane / generate-paths.sh
Last active March 18, 2018 15:18
Generate a space-delimited list of paths for Facebook's batch invalidator
# If you have a static site with just html files and have a setup which allows
# you to access pages with pretty URLs (e.g. /about/) without the index.html
# extension, this will generate the list of paths, which you can paste straight
# into the Facebook batch invalidator.
# If you are not a Mac user, you can change pbcopy to your choice of tool to
# copy to clipboard, or remove it and just copy manually from the command line.
# Just change the values of the FOLDER and DOMAIN vars to your own.
@andycochrane
andycochrane / trains.sh
Created July 18, 2018 18:51
Open National Rail train times in your default browser.
#!/bin/sh
# I would recommend saving this function in your .bash_profile file or wherever you keep your custom functions.
# Alternatively you could save this in a shell script file.
# The function takes up to 4 arguments. FROM, TO, TIME & DATE. Change the defaults below to whatever suits you.
# With no arguments passed this will get you the next trains between the default (Leeds and Kings Cross) stations.
# This works in a bash shell on Mac OSX. If you are not a Mac user, replace the "open" command with whichever one works on your platform.
/*
* Function with options object parameter
*
* Dependencies
* ------------
* An extend helper function or the jquery extend method to merge the defaults
* and options objects.
*
* 1. Merge defaults and options objects into new settings object.
* 2. Assign variables to settings properties.
@andycochrane
andycochrane / count-videos-on-page.js
Last active September 24, 2018 13:59
Create an alert with the number of YouTube and Vimeo videos on the current page.
/**
* Create an alert with the number of YouTube and Vimeo
* videos on the current page.
*/
function countVideosOnPage() {
var iframes = document.getElementsByTagName("iframe");
var youtubeVideos = [];
var vimeoVideos = [];