MySQL: Dump DB with todays date in filename

mysqldump -uUSER_NAME -pPASSWORD DB_NAME > DB_NAME_`date +%Y%m%d%H%M%S`.sql

I love a good dump me. This will dump schema and data.

OS X: Show all files

defaults write com.apple.Finder AppleShowAllFiles TRUE

Stop Steve Jobs hiding files from you.

svn: list files changed in a revision

svn log -v -r 1178

Where revision number is 1178. For more svn info read the online subversion book.

svn: show commits for particular user

svn log | sed -n ‘/pxg/,/—–$/ p’

The above code will show all entries in the log for the user pete.

Linux: List files by time

ls -lt

Or you can flip reverse it:

ls -ltr

Vim: Find number of matches in a file

:%s/pete//gn

In the above example we are looking for the number of matches for the word “pete”.

Linux: pwd show real location (not symlink)

pwd -P

Use the physical flag luke!

OS X: Stop MySQL

sudo /Library/StartupItems/MySQLCOM/MySQL stop

OS X: Remove 3D Dock

defaults write com.apple.dock no-glass -boolean YES; killall Dock

PHP monitor server log

PHP monitor server log

Occasionally you'll be working on a webserver and not have SSH access to it. Below is a simple script I've written that reads a server log (in this case the error log) and outputs a portion of it to a webpage.

PHP:
  1. $no_lines = 25;
  2.  
  3. $filename = $_SERVER['DOCUMENT_ROOT']."/../logs/error.log";
  4. $handle = fopen($filename, "r");
  5. $contents = fread($handle, filesize($filename));
  6. fclose($handle);
  7.  
  8. $contents = trim($contents, "\n");
  9. $contentsArr = explode("\n", $contents);
  10. $size = sizeof($contentsArr);
  11. $n = $size - $no_lines;
  12.  
  13. <h1>monitor log</h1>
  14. ";
  15. <ol start=\"$n\">";
  16.  
  17. for ($n; $n<$size; $n++)
  18. {
  19.     <li>".$contentsArr[$n]."</li>
  20. ";
  21. }
  22.  
  23. echo "</ol>
  24. ";

Obviously in a production environment you'd want to add some sort of password protection to such a script.

/* Pete Graham */