Ryan Detzel

Snippets

Various code snippets I find useful and often have to lookup.

Bash/Linux Stuff

Move files that are older than 60 days to another directory
1
2
3
find $dir1 -type f -mtime +60 -exec mv -v {} $dir2 \;
OR
find / -type f -size +20000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }'
Ubuntu important updates
1
2
sudo apt-get update
sudo unattended-upgrade
Find files that are larger than 10M in the current directory
1
find . -type f -size +10000k -exec ls -lh {} \; | awk '{ print $5, $8 }'

JavaScripts

shorthand for document.ready.
1
2
3
$(function (){
    // your code
});
check if an element exists
1
if ($('#myDiv).length) {

Python

String formating

strftime, I always forget this…
1
datetime.now().strftime("%Y-%m-%d")

Git

stash
1
2
3
4
git stash
git stash list
git stash apply
git stash apply stash@{2}
check current branch vs origin/master HEAD
1
2
git diff origin/master
git log origin..HEAD
revert entire branch
1
2
3
4
5
6
7
8
git checkout SHA-HASH
git checkout master2
git push origin master2
git branch -D master
git push origin :master
git checkout -b master
git pull origin master2
git push origin master
soft commit (undo the last commit you just did)
1
git reset HEAD~1

MySQL

Table size
1
2
3
4
5
6
7
8
SELECT concat(table_schema,'.',table_name),
concat(round(table_rows/1000000,2),'M') rows,
concat(round(data_length/(1024*1024*1024),2),'G') DATA,
concat(round(index_length/(1024*1024*1024),2),'G') idx,
concat(round((data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(index_length/data_length,2) idxfrac
FROM information_schema.TABLES   where table_schema = "DATABASENAME"
ORDER BY data_length+index_length DESC LIMIT 20;