Skip to content

Instantly share code, notes, and snippets.

Brian Dixon bjdixon

Block or report user

Report or block bjdixon

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bjdixon
bjdixon / gist:f30d35fa769192d78c96ef53a6c7a27a
Created Nov 29, 2018
Track down where your disk space has gone
View files_using_disk_space.sh
sudo du -cha --max-depth=1 / | grep -E "M|G"
@bjdixon
bjdixon / build_scp_commands.sh
Last active May 7, 2018
build a list of scp commands for all changed files. Could | sh instead of > ./scp_changed to just invoke the scp commands instead.
View build_scp_commands.sh
git status --porcelain | awk '{if($1!="D") {print "scp " $2 " host:/var/www/host_dir/" $2 } }' > ./scp_changed
@bjdixon
bjdixon / prettygitlog.sh
Created Mar 23, 2018
pretty graph git log
View prettygitlog.sh
git log --all --decorate --oneline --graph
View zipunzip.sh
zip -r myarch.zip mydir/*
unzip myarch.zip -d destination_folder
@bjdixon
bjdixon / scp.sh
Created Feb 12, 2018
recursive download of directory
View scp.sh
scp -r user@your.server.example.com:/path/to/foo /home/user/Desktop/
@bjdixon
bjdixon / keyByValue.js
Created Dec 26, 2017
Get the key for a value in an object
View keyByValue.js
const getKeyByValue = (obj, value) => Object.keys(obj).find(key => obj[key] === value);
@bjdixon
bjdixon / action.js
Created Oct 19, 2017
Alternative to switch statements in reducers
View action.js
import { LANGUAGE, COUNTRY } from './constants';
export const setLanguage = language => ({
type: LANGUAGE,
language
});
export const setCountry = country => ({
type: COUNTRY,
country
});
@bjdixon
bjdixon / pick.js
Last active May 31, 2017
create a new object extracting only desired properties from a source object. eg pick(['name', 'age'], {name: 'hi', age: 42, alive: true}) == {name: 'hi', age: 42}
View pick.js
const pick = (props, obj) => props.reduce((acc, curr) => ({ ...acc, ...{[curr]: obj[curr]} }), {});
@bjdixon
bjdixon / buildObj.js
Created May 17, 2017
Initialise a nested object from an array of keys
View buildObj.js
const build = path => path.reduceRight((o, i) => Object.assign({}, {[i]: o}), {})
@bjdixon
bjdixon / round.js
Created May 17, 2017
Rounding floating point or fixed precision numbers in Javascript
View round.js
// returns a string. fixed is an optional boolean flag to switch on fixed precision or not.
// If you want a number instead of a string prepend the unary plus operator, but then fixed precision cannot be guaranteed.
// -0.1 * 0.2 === -0.020000000000000004
// round(-0.1 * 0.2, 3, true) === "-0.020"
// round(-0.1 * 0.2, 3) === "-0.02"
// +round(-0.1 * 0.2, 3) === -0.02
// +round(-0.1 * 0.2, 3, true) === -0.02
const round = (value, decimals, fixed) => {
const r = Number(Math.round(value + 'e' + decimals) + 'e-' + decimals)
return fixed ? r.toFixed(decimals) : r + ''
You can’t perform that action at this time.