Fork me on GitHub

Nokogiri, RVM, Homebrew and headhache!!!

Thanks to a gist (which I forked and slightly changed) I was able to finally install Nokogiri on my mac:

export BREW_HOME=/usr/local

brew install libxml2
brew link libxml2
brew install https://github.com/adamv/homebrew-alt/raw/master/duplicates/libxslt.rb
brew link libxslt
brew install libiconv
brew link libiconv
gem install nokogiri -- --with-xml2-dir=$BREW_HOME/Cellar/libxml2/2.7.8 --with-xslt-dir=$BREW_HOME/Cellar/libxslt/1.1.26 --with-iconv-dir=$BREW_HOME/Cellar/libiconv/1.13.1/

If you had MacPorts previously installed, it might still not work so
sudo mv /opt/local /opt/local_old
and try again.

Enjoy :)

 

 

OpenVPN at startup in OSX

The easiest way of getting an OpenVPN client on mac is with Tunnelblick but you will join the VPN only when you have logged in. Sometimes you need your mac to connect at startup instead and I’ll show you how to do it:

create /etc/rc.local and copy/paste the following three lines in it:

#!/bin/bash
/sbin/kextload /Applications/Tunnelblick.app/Contents/Resources/tap.kext
/sbin/kextload /Applications/Tunnelblick.app/Contents/Resources/tun.kext

then create a Launch script like this for each of the vpn you want to connect to, replacing YOURVPNNAME, YOURCONFIGFILE, YOUR/CONFIG/FOLDER accordingly:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.openvpn.YOURVPNNAME</string>
<key>OnDemand</key>
<false/>
<key>Program</key>
<string>/Applications/Tunnelblick.app/Contents/Resources/openvpn</string>
<key>ProgramArguments</key>
<array>
<string>openvpn</string>
<string>--config</string>
<string>YOURCONFIGFILE.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>TimeOut</key>
<integer>90</integer>
<key>WorkingDirectory</key>
<string>YOUR/CONFIG/FOLDER</string>
</dict>
</plist>

save each script into /Library/LaunchDaemons/ folder using a name for the file like org.openvpn.YOURVPNNAME.plist, then change the user and group to root:wheel with the following command in a terminal window:

sudo chown root:wheel /Library/LaunchDaemon/org.openvpn.YOURVPNNAME

last commands to register and execute your Launch scripts are:

sudo launchctl load /Library/LaunchDaemon/org.openvpn.YOURVPNNAME.plist
sudo launchctl start org.openvpn.YOURVPNNAME

a restart should be the very last thing to do and once your mac has started you shoud be connected to your vpn network(s)!

enjoy ;)

UPDATE: the new version of tunnelblick 3.2beta26 does have the the “connect when computer starts” functionality that automatically makes this post obsolete. I’ll just keep it for the records :)

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.

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 !

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!

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.

;)

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! :)

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!

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;

Lazy explanation as usual :P

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