A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Elementary JSON

{
"Image": {
"Width":800,
"Height":600,
"Title":"View from 15th Floor",
"Thumbnail":
{
"Url":"http:\/\/scd.mm-b1.yimg.com\/image\/481989943",
"Height": 125,
"Width": "100"
},
"IDs":[ 116, 943, 234, 38793 ]
}
}

Thanks Yahoo!

View the swap file usage in linux

/sbin/swapon -s

Reasons not to use stored procedures in databases

http://www.tonymarston.net/php-mysql/stored-procedures-are-evil.html

Coloured log output

Tail the log and pipe it through this:

#!/usr/bin/perl

use warnings;
use strict;
use Term::ANSIColor qw(color);

while( <> ) {
chomp;
s/\t/ /g;
(/ERROR|failed/) && do {
print( color( 'red' ). $_ .color( 'reset' )."\n" );
next;
};
(/WARN/) && do {
print( color( 'magenta' ). $_ .color( 'reset' )."\n" );
next;
};
(/succeeded/) && do {
print( color( 'green' ). $_ .color( 'reset' )."\n" );
next;
};
(/INFO/) && do {
print( color( 'yellow' ). $_ .color( 'reset' )."\n" );
next;
};
(/DEBUG/) && do {
print( color( 'blue' ). $_ .color( 'reset' )."\n" );
next;
};
print $_."\n";
}

Taking Screenshots in Mac OS X

http://guides.macrumors.com/Taking_Screenshots_in_Mac_OS_X

Shortcuts

* Command-Shift-3: Take a screenshot of the screen, and save it as a file on the desktop
* Command-Shift-4, then select an area: Take a screenshot of an area and save it as a file on the desktop
* Command-Shift-4, then space, then click a window: Take a screenshot of a window and save it as a file on the desktop
* Command-Control-Shift-3: Take a screenshot of the screen, and save it to the clipboard
* Command-Control-Shift-4, then select an area: Take a screenshot of an area and save it to the clipboard
* Command-Control-Shift-4, then space, then click a window: Take a screenshot of a window and save it to the clipboard

In Leopard, the following keys can be held down while selecting an area (via Command-Shift-4 or Command-Control-Shift-4):

* Space, to lock the size of the selected region and instead move it when the mouse moves
* Shift, to resize only one edge of the selected region
* Option, to resize the selected region with its center as the anchor point

Can't connect to MySQL

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Reason: mysqld is not running!

How to see the answers for free on Expert Exchange

http://www.experts-exchange.com

Solution:
Scroll down

Code folding in vi

All you ever wanted to know about code folding in vim, including keys: http://www.linux.com/archive/articles/114138

Config settings for code folding: http://smartic.us/2009/04/06/code-folding-in-vim/

Vim documentation for folding: http://www.vim.org/htmldoc/fold.html
There are six methods to select folds:

manual manually define folds
indent more indent means a higher fold level
expr specify an expression to define folds
syntax folds defined by syntax highlighting
diff folds for unchanged text
marker folds defined by markers in the text

Key concepts:
  • To use the indent method you need to set the :tabstop correctly
  • Syntax method requires the correct syntax files to be present
Commands:
  • zc -> close fold
  • zo -> open fold

How to talk to memcached

  1. telnet to the server (or localhost) on the right port
  2. type "flush_all" to invalidate the whole cache
  3. type "delete [key]" to invalidate a particular item
See also the memcache protocol