Skip to content

Instantly share code, notes, and snippets.

@bjdixon
bjdixon / files_using_disk_space.sh
Created November 29, 2018 04:36
Track down where your disk space has gone
sudo du -cha --max-depth=1 / | grep -E "M|G"
@bjdixon
bjdixon / build_scp_commands.sh
Last active May 7, 2018 05:23
build a list of scp commands for all changed files. Could | sh instead of > ./scp_changed to just invoke the scp commands instead.
git status --porcelain | awk '{if($1!="D") {print "scp " $2 " host:/var/www/host_dir/" $2 } }' > ./scp_changed
@bjdixon
bjdixon / prettygitlog.sh
Created March 23, 2018 03:43
pretty graph git log
git log --all --decorate --oneline --graph
@bjdixon
bjdixon / zipunzip.sh
Created March 23, 2018 03:14
zip/unzip
zip -r myarch.zip mydir/*
unzip myarch.zip -d destination_folder
@bjdixon
bjdixon / scp.sh
Created February 12, 2018 03:36
recursive download of directory
scp -r [email protected]:/path/to/foo /home/user/Desktop/
@bjdixon
bjdixon / keyByValue.js
Created December 26, 2017 08:52
Get the key for a value in an object
const getKeyByValue = (obj, value) => Object.keys(obj).find(key => obj[key] === value);
@bjdixon
bjdixon / action.js
Created October 19, 2017 04:49
Alternative to switch statements in reducers
import { LANGUAGE, COUNTRY } from './constants';
export const setLanguage = language => ({
type: LANGUAGE,
language
});
export const setCountry = country => ({
type: COUNTRY,
country
});
@bjdixon
bjdixon / buildObj.js
Created May 17, 2017 10:21
Initialise a nested object from an array of keys
const build = path => path.reduceRight((o, i) => Object.assign({}, {[i]: o}), {})
@bjdixon
bjdixon / round.js
Created May 17, 2017 07:49
Rounding floating point or fixed precision numbers in Javascript
// 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 + ''
@bjdixon
bjdixon / pick.js
Last active May 31, 2017 07:33
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}
const pick = (props, obj) => props.reduce((acc, curr) => ({ ...acc, ...{[curr]: obj[curr]} }), {});