1. Exclude files and directories from Apache Auth

    It would have made sense to use LocationMatch with a negative lookahead regex pattern like “^/(?!admin)” but that doesnt work. Neither work a rule like !”^/admin” so here is a workaround:

    <Location "/">  
    AuthType Basic  
    AuthName "Restricted Files"  
    AuthUserFile /var/www/clients/client12/web17/passwd  
    AuthGroupFile /dev/null  
    Require valid-user  
    SetEnvIf Request_URI "^/(admin|skin|js|index)(.*)$" allow  
    SetEnvIf Request_URI "^/favicon.ico$" allow  
    Order allow,deny  
    Allow from env=allow  
    Satisfy Any  
    </Location>
    
    This basically allow the access without authentication to the directories/files that start with admin, skin, js or index. The other rule allow the favicon too. …


  2. VIM and the clipboard on Ubuntu

    If you want to copy and paste from Vim to the clipboard, install the package vim.gtk and enjoy the command “+y ! …


  3. Rails and PostgreSQL

    Complaining, screaming, sweating, swearing …. why it doesnt work … jeeeeeezzz

    /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in 
    
    establish_connection’: Please install the postgres adapter:
    gem install activerecord-postgres-adapter
    
    (no such file to load – active_record/connection_adapters/postgres_adapter) (RuntimeError) ``` And then a light … “I upgraded postgresql recently!” Just reinstall the postgres gem and you are done… What a night! …


  4. map and grep: from Perl to PHP

    Probably many of you already know but here is the correspondent in PHP of the two fundamentals Perl functions:

    map => array_map  
    grep => array_filter
    
    Too lazy to give you examples .. I think you can work it out yourself. ;) …


  5. PHP-FPM on Ubuntu Lucid Lynx

    I have been using the dotdeb repository on karmic for a while, but today, when I installed the new Lucid Lynx, it just became a mess so I decided to keep all the original ubuntu packages (Lucid ships php 5.3.2) and find an alternative repo for php-fpm which I use on my dev machine.
    Here it is:Brian’s php5-fpm : Brian Mercer Happy 10.04! :) …


  6. Google Website Optimiser and the bugged Techie Guide

    I spent hours yesterday to implement the GWO that, instead, should take literally minutes!
    You want to know why? The bugged Techie Guide!!! On page 19, the script is completely wrong and drove me mad: variation-content should be variation_content and document.write(“</nosc” + “ript>”) should be document.write(“<nosc” + “ript>”); So, here is he complete correct script:

    <script>  
    var v = utmx(‘variation_content’, ‘Section1’);  
    if (v) {  
    document.write(  
    v.replace(“%%product_name%%”, “<? print $product_name ?>”).  
    replace(“%%product_price%%”, “<? print $product_price ?>”).  
    replace(“%%product_id%%”, “<? print $product_id ?>”));  
    document.write(“<nosc” + “ript>”);  
    }  
    </script>  
    <ul>  
    <li>Product name: <? print $product_name ?>  
    <li>Product price: <? print $product_price ?>  
    <li><a href=’buy.php?prod-id=<? print $product_id ?>’>  
    Buy Now</a>  
    </ul>  
    </noscript>  
    
    Adapt it to your code and be happy! …


  7. Nginx and $_SERVER['HTTPS']

    When you are using the FastCGI Php version, you would set HTTPS variable if you are serving parts of you website with SSL. To do that, add the following function into the http section of your nginx configuration

    map $scheme $fastcgi_https { ## Detect when HTTPS is used
    default off;
    https on;
    }
    
    and use the variable into your server section
    fastcgi_param  HTTPS $fastcgi_https;
    


  8. svn: Inconsistent line ending style

    I hate svn! It’s official! if you have this stupid error, what you have to do is run dos2unix on the file specified by the error. Don’t forget the -a option!

    shell$ dos2unix -a /the/affected/file.php 
    


  9. upstream sent too big header while reading response header from upstream

    if you have this error from nginx with php-fpm and output_buffers = On in your php.ini then try to increment the buffer size in nginx:

      
    fastcgi_buffers 8 16k;  
    fastcgi_buffer_size 32k;  
    


  10. BASH: rename files

    A simple rename example using again the mighty awk and xargs

    ls -l *.xml | awk '{print $9}' | xargs -t -i mv {} {}.old
    
    Explanation:
    **
    ls -l *.xml
    
    ** -> easy! list the xml files in a folder
    **
    awk '{print $9}'
    
    ** -> output just the name of the file
    **
    xargs -t -i mv {} {}.old
    
    ** -> rename it adding at the same filename the extension “.old” I know, I know … my explanation is crap: blame my laziness :) …