Archive for April, 2008

python/perl/unix one liners

Friday, April 25th, 2008

Here are some cool python one liners.

  • Parse apache log using python: print 5th field
    python -c “import csv,sys;f=csv.reader(sys.stdin, delimiter=’ ‘); print ‘\n’.join([r[5] for r in f])
  • Generate frequency histogram from a text files of terms
    cat file.txt | sort | uniq -c | sort -rn
  • print 2nd column of a tab separated file
    awk -F”\t” ‘{print $2}’
  • perl search replace from files
    perl -i -p -e ’s/old/new/g’

Website performance

Thursday, April 24th, 2008

These are some quick apache tips to improve the performance of your web site:

  1. compress your html/css/js content by making these changes to your httpd.conf
    SetOutputFilter DEFLATE
    AddOutputFilterByType DEFLATE text/html text/css application/x-javascript

    To see it working, install livehttpheaders addon in firefox, open Tools->Live HTTP headers, and fetch http://www.technologydb.com/. In case some headers are missing, clear your firefox cache. Here are the screenshots:

    firefox header gzip html

    firefox header gzip css

  2. cache images, css and js
    ExpiresByType text/css “access plus 240 hours”
    ExpiresByType image/jpeg “access plus 24 hours”
    ExpiresByType image/jpg “access plus 24 hours”
    ExpiresByType image/gif “access plus 24 hours”
    ExpiresByType application/x-javascript “access plus 24 hours”

    This will avoid browser making an http call to server for these content types.

  3. Avoid using too many domain names. Each domain require a DNS lookup which is expensive.
  4. Keep limited number of css and javascripts files. Browsers generally limit parallel number of fetches.

For a full list of advanced tips on website performance you can view this excellent page maintained by Yahoo Exceptional Performance (http://developer.yahoo.com/performance/)

Hello world!

Wednesday, April 23rd, 2008

Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!