Skip to content

Instantly share code, notes, and snippets.

@bjdixon
bjdixon / path.js
Created May 9, 2017 05:26
Use a path to get a nested value in an object. eg. obj.user.address.city == path(['user', 'address', 'city'], obj)
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 April 11, 2017 08:06
create a mysql server in a docker container
docker run --detach --name instance-of-mysql -p 3306 -e MYSQL_ROOT_PASSWORD=secretPw -d mysql
@bjdixon
bjdixon / update_if_already_inserted.sql
Created March 30, 2017 08:05
Insert a record, if the pk already exists then update the record
INSERT IN tablename (id, val1, val2) VALUES (1, 'a', 'b')
ON DUPLICATE KEY UPDATE val1 = 'a', val2 = 'b';
@bjdixon
bjdixon / nginx.conf
Created March 28, 2017 08:46
nginx conf location block when using react router
location / {
try_files $uri $uri/ /index.html;
}
@bjdixon
bjdixon / remove_extended_attrs.sh
Created March 23, 2017 08:03
remove extended attributes from files in mac os
xattr -rc ./*.png
@bjdixon
bjdixon / backup-and-restore-mongodb.sh
Created February 14, 2017 08:10
Download and restore mongo database from remote host
# 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 February 8, 2017 02:54
crontab examples with path. Edit with crontab -e, list with crontab -l
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 February 7, 2017 04:10
determine which device was used for a given mount
df -h /home
@bjdixon
bjdixon / filesize.sh
Created February 7, 2017 04:08
Sum file size for files matching a pattern
du -hc ./*.py
@bjdixon
bjdixon / rebase.sh
Created October 12, 2016 09:35
rebase from upstream
git pull --rebase upstream master