Skip to content

Instantly share code, notes, and snippets.

View tgallacher's full-sized avatar

Tom Gallacher tgallacher

View GitHub Profile
@tgallacher
tgallacher / git-prune-branches.sh
Last active March 27, 2019 01:17
Git alias to prune branches
# Clean up branches which no longer exist on the remote
#
# @tip: Add to bash/zsh aliases
# @note: split over multiple lines to make it easier to read.
# @see: https://gist.github.com/tgallacher/cae12db973a235b52e9e5b014d21d633
git fetch && \
git remote prune origin && \
git branch -v | \
grep gone | \
awk '{print $1;}' | \
@tgallacher
tgallacher / .gitconfig
Last active December 7, 2018 20:21
Useful Git config alias / config
alias.co=checkout
alias.ci=commit
alias.st=status -s
alias.br=branch
alias.last=log -1 HEAD
# Pretty oneline log summary
alias.plog=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
# Word-level diff
@tgallacher
tgallacher / aliases.zsh
Created October 29, 2018 12:19
Shell aliases
# Remove merged branches from local repo.
alias git_prune_branches='git fetch && git remote prune origin && git br -v | grep gone | awk '"'"'{print $1;}'"'"' | xargs -n 1 git br -d'
@tgallacher
tgallacher / sorting-algos-summary.js
Created May 7, 2018 21:35
Summary of basic sorting algo. implementations
// Basic summary of different common sorting algorithms.
// This is just for reference; focus in not on micro-optimising the algo, but just generally highlighting the
// differences between each algorithm.
//
// Summaries from Brian Holt's CodePen's
//
// ToCs
// 1. Bubble Sort
// 2. Insertion Sort
// 3. Merge Sort (effectively what Array.prototype.sort uses under the hood (95% of the time))

Keybase proof

I hereby claim:

  • I am tgallacher on github.
  • I am tgallacher (https://keybase.io/tgallacher) on keybase.
  • I have a public key ASAo0nB6NZAxdEu6lz_ZvG_v6xpz1tnSEjBp_4SPwFehAwo

To claim this, I am signing this object:

@tgallacher
tgallacher / medium-post--es6-variable--const-obj-reassignment.js
Created August 24, 2017 22:26
Supplementary code snippet for Medium post
// Define our 'constant' variable
const data = {
a: 1,
b: 2
};
// Let's mutate its contents: All Perfectly acceptible!
data.b = 5;
data.d = 'foo';
delete data['a'];
@tgallacher
tgallacher / medium-post--es6-variable-and-redux-problem--const.js
Last active August 24, 2017 22:26
Supplementary code snippet for Medium post
function foo(){
const bar = 5;
if(true){
const bar = 100;
bar = 20; // TypeError: Assignment to constant variable
}
console.log(bar); // would have printed: 5
@tgallacher
tgallacher / medium-post--es6-variable-and-redux-problem--let.js
Last active August 24, 2017 22:26
Supplementary code snippet for Medium post
function foo(){
let bar = 5;
if(true){
let bar = 100;
}
console.log(bar); // prints: 5
}
@tgallacher
tgallacher / medium-post--es6-variable-and-redux-problem--var.js
Last active August 24, 2017 22:26
Supplementary code snippet for Medium post
function foo(){
var bar = 5;
if(true){
var bar = 100; // Even though var isn't block scoped, this doesn't throw an error!
}
console.log(bar); // prints: 100
}