Friday, November 12, 2010

beautifying my code

these changes give more legibility to code:

sed script to change:

  • if( -> if (
  • if....){ _> if...) {
  • }else -> } else
  • else{ -> else {
  • for( -> for (
  • for...){ -> for...) {

find . -type f -name "*.php" -exec sed -i -e 's/if(/if (/g' -e 's/if\(.*\)){/if\1) {/g' -e 's/for(/for (/g' -e 's/for\(.*\)){/for\1) {/g' -e 's/else{/else {/g' -e 's/}else/} else/g' {} \;

I had forgotten "foreach":

find . -type f -name "*.php" -exec sed -i -e 's/foreach(/foreach (/g' -e 's/foreach\(.*\)){/\1) {/g' {} \;





sed script to trim trailing spaces:

find . -type f -name "*.php" -exec sed -i 's/[ \t]*$//' {} \;



this may also be handy, to strip ^M characters:
(from http://www.computing.net/answers/unix/remove-m-and-line-feeds/6934.html)
anupam May 23, 2005 at 21:11:55 Pacific

Hi..to remove ^M, give the command :
sed -e 's/^M//g' filename
you will have to write the control-M as follows : first press control-V,then control-M,this will show the correct control-M on the command line.
For removing the linefeeds,try this :
sed -e 's/.$//g' filename
this will remove the last character from the line,which happens to be the line feed.


Thursday, November 4, 2010

turn on query timing in postgres

11. How to turn on timing, and checking how much time a query takes to execute ?

# \timing — After this if you execute a query it will show how much time it took for doing it.
# \timingTiming is on.

# SELECT * from pg_catalog.pg_attribute ;
Time: 9.583 ms
 
 
more stuff on: http://www.thegeekstuff.com/2009/04/15-practical-postgresql-database-adminstration-commands/