Skip to content

Instantly share code, notes, and snippets.

@bjdixon
bjdixon / path.js
Created May 9, 2017
Use a path to get a nested value in an object. eg. obj.user.address.city == path(['user', 'address', 'city'], obj)
View path.js
const isObject = item => item && typeof item === 'object' && !Array.isArray(item);
const path = ([...paths], obj) => {
const tmp = obj[paths.shift()];
return !isObject(tmp) || !paths.length ? tmp : path(paths, tmp);
};
@bjdixon
bjdixon / docker_mysql.sh
Created Apr 11, 2017
create a mysql server in a docker container
View docker_mysql.sh
docker run --detach --name instance-of-mysql -p 3306 -e MYSQL_ROOT_PASSWORD=secretPw -d mysql
@bjdixon
bjdixon / update_if_already_inserted.sql
Created Mar 30, 2017
Insert a record, if the pk already exists then update the record
View update_if_already_inserted.sql
INSERT IN tablename (id, val1, val2) VALUES (1, 'a', 'b')
ON DUPLICATE KEY UPDATE val1 = 'a', val2 = 'b';
@bjdixon
bjdixon / nginx.conf
Created Mar 28, 2017
nginx conf location block when using react router
View nginx.conf
location / {
try_files $uri $uri/ /index.html;
}
@bjdixon
bjdixon / remove_extended_attrs.sh
Created Mar 23, 2017
remove extended attributes from files in mac os
@bjdixon
bjdixon / backup-and-restore-mongodb.sh
Created Feb 14, 2017
Download and restore mongo database from remote host
View backup-and-restore-mongodb.sh
# Download copy of database from remote host
mongodump --host mongo.hostname.com --db database-name --port 27017 --username user --password pwd --out /opt/backup/mongodump
# Restore copy of database to remote host
mongorestore --host mongo.hostname.com --db database-name --port 27017 --username user --password pwd /opt/backup/mongodump/database-name
@bjdixon
bjdixon / cron.sh
Created Feb 8, 2017
crontab examples with path. Edit with crontab -e, list with crontab -l
View cron.sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
*/5 * * * * /path/to/job/to/run/every/five/minutes
0 9 * * * /path/to/job/to/run/every/day/at/9am
0 9 * * * . /source/doesnt/work/so/use/dot/script.sh
0 9 * * * /path/script.sh >> /var/log/output_and_errors.log 2>&1
@bjdixon
bjdixon / mount_device.sh
Created Feb 7, 2017
determine which device was used for a given mount
@bjdixon
bjdixon / filesize.sh
Created Feb 7, 2017
Sum file size for files matching a pattern
View filesize.sh
du -hc ./*.py
@bjdixon
bjdixon / rebase.sh
Created Oct 12, 2016
rebase from upstream
View rebase.sh
git pull --rebase upstream master
You can’t perform that action at this time.