Skip to content

Instantly share code, notes, and snippets.

View devm33's full-sized avatar
:copilot:

Devraj Mehta devm33

:copilot:
View GitHub Profile
@devm33
devm33 / shell_well.sh
Last active October 10, 2015 22:12
Doing things well in shell
# Display summarized (s) human-readable (both h) sizes of sub-directories sorted descending
# - remove / to include files in that folder
# - remove r to sort ascending by size
du -sh */ | sort -hr
# Remove broken symlinks (leverages zsh)
rm -- *(-@D)
@devm33
devm33 / backup_home.sh
Last active December 19, 2020 04:11
Bash script to backup home directories using rsync
#!/usr/bin/env bash
# Script to backup the home directory to an external hardrive mounted at /media/backup
# Uses rsync, dpkg, and mail (for error logging)
SRC='/home/*'
DEST='/media/backup'
RSYNC_OPTS='-haAXuv --delete'
EXCLUDE='*/.cache/* */.thumbnails/* */.config/google-* lost+found .gvfs'
EXCLUDE="$(echo $EXCLUDE | sed 's/\(\S\+\)/ --exclude \1/g')"
@devm33
devm33 / date_local.js
Created March 9, 2014 09:27
Puts the local time date in a format the W3 is happy with. Disclaimer, I was not made any happier by writing this.
var zeroPad = function(str) {
return ('0'+ str).slice(-2);
};
var dateLocal = function() {
var d = new Date();
var s = d.getFullYear() + '-';
s += zeroPad(d.getMonth()) + '-';
s += zeroPad(d.getDate()) + 'T';
s += zeroPad(d.getHours()) + ':';
s += zeroPad(d.getMinutes()) + ':';
@devm33
devm33 / rand_string.node.js
Last active March 3, 2022 09:00
Generate Random Hex String in NodeJS
function rand_string(n) {
if (n <= 0) {
return '';
}
var rs = '';
try {
rs = crypto.randomBytes(Math.ceil(n/2)).toString('hex').slice(0,n);
/* note: could do this non-blocking, but still might fail */
}
catch(ex) {