Check out my latest project: Code Dumper

Archive for the 'Dump' Category

Thousand separator regex

s/\d{1,3}(?=(\d{3})+(?!\d))/$&,/g The amount of code that goes in to formatting numbers can be silly sometimes, especially when you realise it can be done as a regex. Note that if the number has a DP longer than 2, it'll format it - I suggest splitting out the DP first, and bash them back together. (via)

to hex

d.toString(16) Beautifully simple way to get a hex value from a number. Note that d is a number. If you want a string as a hex XML valid code, use: '&#x' + parseInt(number).toString(16).toUpperCase() + ';'

Restart lookupd (to refresh dns cache)

ps ax | grep lookupd | grep -v grep | perl -ne 'split; print $_[0]' | xargs sudo kill -HUP I'm often connecting to different networks depending on what job I'm doing, and sometimes I'll need to tweak my /etc/hosts file. Since my system will cache DNS lookups, I'll need to restart lookupd, and this [...]

MySQL dump tables like...

mysql $DB -u$USERNAME -p$PASSWORD -e 'show tables like "$LIKE%"' | grep -v Tables_in | xargs mysqldump --add-drop-table $DB -u$USERNAME -p$PASSWORD Replace dollar variables with your details to drop a group of tables. Useful when you've got one database hosting a number of different web sites and you need a dump of a particular site.