Archive for June, 2008

MySQL slow queries log

Friday, June 20th, 2008

The slow query log consists of all SQL statements that took more than long_query_time seconds to execute.

See manual

Make your bash prompt red for deploy user on production servers

Thursday, June 19th, 2008

If you’re working on several machines, it’s a good practice to use different prompt colors.

For instance I would leave the prompt normal on my personal development machine, but I would make my prompt yellow on the staging server, and most of all, red on the production servers.

Just to remind me I should think twice before committing commands.

Here’s how to make it red (color code 0;31):

[deploy@sw29 abstracted]$ echo $PS1
[\u@\h \W]\$
[deploy@sw29 abstracted]$ export PS1="\e[0;31m[\u@\h \W]\$ \e[m "
[deploy@sw29 abstracted]

Here’s how to make it yellow (color code 0;33):

[deploy@sw29 abstracted]$ export PS1="\e[0;33m[\u@\h \W]\$ \e[m "
[deploy@sw29 abstracted]


Opaque to transparent gradient on layers in GIMP

Thursday, June 19th, 2008

1. Turn on Alpha channels (Layers/Transparency/Add alpha channels) if not already done
2. Click on the Gradient tool (L shortcut)
3. In the toolbox window under the tools appears the properties for the Gradient tool.
4. Click on the big rectangular icon and you see the setting by default is usually FG to BG (meaning the gradient will appear between the foreground color and the background color, with no transparency)
5. In the drop-down list that appeared select “FG to transparent
6. Choose you foreground color
7. On the layer, use the gradient tool by clicking and maintaining the left mouse button, moving the mouse in the direction of the gradient, and releasing the button where you want the gradient to stop (the layer will be totally transparent starting from where the mouse was pointing when you released the button)

Loops in Bash scripting

Wednesday, June 18th, 2008

Here is a quick snippet of bash scripting to build a loop:

for fruit in "apple red" "banana yellow" "pear green"
   set -- $fruit           #parses the variable $fruit and sets the positional vars ($1, $2, $3,...)
   echo "The fruit named $1 is of color $2";

Undo committed changes in SVN

Tuesday, June 17th, 2008

Your last revision 505 of a file should have never happened? You want to revert to 497? Here’s how:

svn merge -r 505:497 bank.php
svn commit

It will bring back locally bank.php to revision 497.
And if you commit right away, it will commit 497, like if commit 505 never happened

Detailed explanation from the SVN manual

Ignore SVN directories in GREP searches

Monday, June 16th, 2008

SVN hidden directories cache a lot of temporary files. Most of the time when you do a recursive GREP you don’t need to go through them.

You can avoid exploring those sub-directories either manually every time you grep:

grep -r --exclude=\*.svn\*

Or set the GREP_OPTIONS environment variable, either in your .bashrc or by exporting it in your command line like so:


Adding this command to .bashrc will make it permanent, even next time you log in again.

The more recent versions of grep (from 2.5.3) have an exclude-dir option:

export GREP_OPTIONS="--exclude-dir=.svn"

Older versions of grep that don’t support the exclude-dir options will return this error:

bash#  grep -R "boo" .
grep: unrecognized option `--exclude-dir=.svn'
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
bash# grep -V
grep (GNU grep) 2.5.1

Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO



Selecting an additional column along with a count(*)

Monday, June 9th, 2008

If you try to print another column than just a count(*) without specifying a GROUP BY clause, you will get this error:

mysql> SELECT description, count(*) FROM my_table WHERE action='post' AND result='fail';
Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause

Just add the name of the extra column you are trying to print in the GROUP BY clause and you’re done:

mysql> SELECT description, count(*) FROM my_table WHERE action='post' AND result='fail' GROUP BY 'description';

This has a practical application in printing a Top 10 of most successful players:

mysql> SELECT name, count(*) FROM my_table WHERE action='fight' AND result='success' GROUP BY 'name' LIMIT 10;

Selecting elements in CSS

Friday, June 6th, 2008

Select by tag name (A)

Select by class (.theclass)

Select by id (#someid)