In: , , , On: 2012 / 11 / 21 Short URL:

I've been speaking lately with folks from Spamhaus about anti spam measure in YOURLS and a YOURLS plugin for this. Currently the #1 result in Google for "spamhaus PHP" is a post on Lockergnome which gets it totally wrong and provides a script that does not work, so here is a PHP script that does work.

This script checks a URL (its domain part, in fact) against the 3 major black lists: Spamhaus, SURBL and URIBL.

The script:

  1. /**
  2.  * Check a URL against the 3 major blacklists
  3.  *
  4.  * @param string $url The URL to check
  5.  * @return mixed true if blacklisted, false if not blacklisted, 'malformed' if URL looks weird
  6.  */
  7. function ozh_is_blacklisted( $url ) {
  9.     $parsed = parse_url( $url );
  11.     if( !isset( $parsed['host'] ) )
  12.         return 'malformed';
  14.     // Remove www. from domain (but not from
  15.     $parsed['host'] = preg_replace( '/^www\.(.+\.)/i', '$1', $parsed['host'] );
  17.     // The 3 major blacklists
  18.     $blacklists = array(
  19.         '',
  20.         '',
  21.         '',
  22.     );
  24.     // Check against each black list, exit if blacklisted
  25.     foreach( $blacklists as $blacklist ) {
  26.         $domain = $parsed['host'] . '.' . $blacklist . '.';
  27.         $record = dns_get_record( $domain );
  29.         if( count( $record ) > 0 )
  30.             return true;
  31.     }
  33.     // All clear, probably not spam
  34.     return false;
  35. }


  1. if( ozh_is_blacklisted( $url ) ) {
  2.     // do something brutal (eg die() your script, yell at user, etc...)
  3. }
  5. // all is fine *for today*, do your regular stuff.
  6. // This said, it'd be nice to recheck every couple of days

Feel free to steal.

In: , , , On: 2012 / 11 / 13 Short URL:

I'm a SVN user.

Nowadays, all the cool kids have a Github account where they host stuff and use Git as their primary Source Control tool, and prefer it over the usual SVN you've probably got to use.

I'm not a cool kid and for the last few years (since WordPress started the plugin repository using SVN I think — more or less 8 years ago), I've been happily using SVN. You know SVN, right? Easy to use and to understand, right? Does the job simply, right? So, why switch, right?

I'm regularly pestered to move YOURLS from Google Code to Github, to which I responded more or less that I was happy with SVN and I didn't want to spend time learning a new complicated tool. Because, Git is complicated, right?

But I wanted to be a cool kid anyway, so I gave Git a few looks and tries.

Read More

There's a really nice post that's getting shared all over the intarnets right now, showcasing useful keyboard tricks in various editors, but I thought it missed Notepad++ which does support most of those tricks out of the box.

I decided to list a few quick keyboard tricks in Notepad++ I use daily, and there are really a few cool ones.

Delete whole words

Delete previous word: Control + Backspace
Delete next word: Control + Delete

Actually I think that works in any Windows application since it works right here in my WordPress Write interface.

More power: you can delete from carret to start of line or to end of line adding Shift in the combo:

Delete to start of line: Control + Shift + Backspace
Delete to end of line: Control + Shift + Delete

Duplicate or delete current line

Duplicate current line: Control + D
Delete current line: Control + L

I use the first one pretty often, especially when wanting to test something slightly different: duplicate line, comment first one out and slightly alter second one. Which goes along really well with next trick:

Comment or uncomment one or several lines

Comment or uncomment: Control + Q

That one toggles a leading // in current line or for a line selection. You can also add "stream comments" (ie /* stuff */) with the following key combo:

Add stream comment: Shift + Control + Q

Move that line

Switch current and previous line: Control + T
Move whole line to another place: Shift + Control + Up or Shift + Control + Down

The totally cool stuff is, that second trick works with a multiple line selection. This works great to move an entire small function or CSS declaration.

Column Editing

I've always thought that one was insane :) Pretty usefull if you want to edit several lines of a file where the same text is repeated, such as a CSS file.

Column selection: Alt + Left Click

Where does that code block starts or end? Find matching brace

Go to matching brace : Control + B

Of course the highlighting helps but when the block is taller than your screen, it's not enough. That one is one of my favorites, it makes navigation in if then else or function blocks really easy.

Automatic indentation

Select several lines and move them to the right (indent) or to the left (unindent? outdent?) in a blink

Indent several lines: Tab
Unindent several lines: Shift + Tab

Scroll through the document without using your mouse

Scroll without changing carret position: Control + Up or Control + Down

More !

That's just a few quick and useful keyboard tricks I use all the time, but there are a lot more. Notepad++ has also a gazillion plugins to do just anything you'd think of. The ones I use all the time are Function List (displays a function list in the sidebar, very handy to quickly navigate) and Finger Text, one of the many snippet plugins available.

In: , , , On: 2012 / 10 / 17 Short URL:

Ho haï, blog, long time no see! :)

I was checking stuff on various URL shorteners and noticed has one interesting feature: you can generate short URLs that are "pronounceable" (no "vgfhgt"). This is a great little touch: a random but pronounceable word will be more memorable and the probability for typos is reduced, which makes it a killer feature for random generated passwords for example.

Generating pronounceable random words isn't difficult :

  • start by a vowel or a consonant
  • alternate and add letters till proper word length

Simple, but this generates words that are too simple maybe: 'abuco', 'misolo', 'xulanipo', etc… Natural words also use a few consecutive consonant combinations as well as vowel combos ('cheepo', 'bergam', …)

I ended up with this simple piece of code that gives more natural words:

  1. <?php
  2. /**
  3.  * Generate random pronounceable words
  4.  *
  5.  * @param int $length Word length
  6.  * @return string Random word
  7.  */
  8. function random_pronounceable_word( $length = 6 ) {
  10.     // consonant sounds
  11.     $cons = array(
  12.         // single consonants. Beware of Q, it's often awkward in words
  13.         'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm',
  14.         'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'z',
  15.         // possible combinations excluding those which cannot start a word
  16.         'pt', 'gl', 'gr', 'ch', 'ph', 'ps', 'sh', 'st', 'th', 'wh',
  17.     );
  19.     // consonant combinations that cannot start a word
  20.     $cons_cant_start = array(
  21.         'ck', 'cm',
  22.         'dr', 'ds',
  23.         'ft',
  24.         'gh', 'gn',
  25.         'kr', 'ks',
  26.         'ls', 'lt', 'lr',
  27.         'mp', 'mt', 'ms',
  28.         'ng', 'ns',
  29.         'rd', 'rg', 'rs', 'rt',
  30.         'ss',
  31.         'ts', 'tch',
  32.     );
  34.     // wovels
  35.     $vows = array(
  36.         // single vowels
  37.         'a', 'e', 'i', 'o', 'u', 'y',
  38.         // vowel combinations your language allows
  39.         'ee', 'oa', 'oo',
  40.     );
  42.     // start by vowel or consonant ?
  43.     $current = ( mt_rand( 0, 1 ) == '0' ? 'cons' : 'vows' );
  45.     $word = '';
  47.     while( strlen( $word ) < $length ) {
  49.         // After first letter, use all consonant combos
  50.         if( strlen( $word ) == 2 )
  51.             $cons = array_merge( $cons, $cons_cant_start );
  53.          // random sign from either $cons or $vows
  54.         $rnd = ${$current}&#91; mt_rand( 0, count( ${$current} ) -1 ) &#93;;
  56.         // check if random sign fits in word length
  57.         if( strlen( $word . $rnd ) <= $length ) {
  58.             $word .= $rnd;
  59.             // alternate sounds
  60.             $current = ( $current == 'cons' ? 'vows' : 'cons' );
  61.         }
  62.     }
  64.     return $word;
  65. }
  67. ?>

(bleh, just noticed the fuckingfancy curled quoted are back in code blocks. pastebin for cut'n'paste code)

Play with the demo: random pronounceable words.

Nothing elaborated enough to help you create an alien language for your next sci-fi movie, but I'm rather pleased with the random words it creates. It's also easy to implement this in another language: modify the group of consecutive vowels and consonants to match what exists in your language.

I recently discovered Rodrigo y Gabriela, a duo of Mexican guitarists playing fast rhythmic acoustic guitars. Think Flamenco on steroids meets furious Rock. I'm totally hooked and want to share :)

The first track a friend introduced to me was their cover of Led Zep's Stairway to Heaven, and I immediately thought "wow, gotta check out more from them"

Being a metal head myself, I looked for more covers and boy I got excited by tons of live performances: Metallica's Orion, One, a quick reference to Slayer's Rain in Blood at the beginning of a song, Symphony of Destruction, Whiskey In The Jar. Do not miss that live jam session with living monster Robert Trujillo, they just fit too nicely together to be skipped.

OK, these guys obviously like classic metal and know how to cheer a live crowd up with hits everyone love. Their studio compositions are just pure awesomeness too.

Hanuman gives me giant goosebumps. Diablo Rojo makes me want to jump all over the place. On Tamacun my head just shakes all by itself. I could just list all their songs.

Seriously, go and search the whole interwebs for more videos of them. They're insanely good. ZOMG when I grow up I want to be a guitarist like Rodrigo :)

Often when viewing a Twitter profile, the same comment pops into my mind: "Does this person follow me?". That's a basic information Twitter profiles still fail to clearly show.

There's a neat site you may know already,, which lets you know if user1 follows user2 in a very simple way: check (example). Simple, but this lacks automation and geek fun. Let's make a cute bookmarklet out of this.
Read More

Look at what the mailman finally brought me today:

OMG. I'm all excited. Writing stuff is great, submitting Word documents for proofreading is great, reviewing PDF chapters is great, downloading the whole ebook is great but, man, holding the hefty nifty paperback, feeling its weight, substance and existence… Wow :)

A few days ago, the fine folks from DigWP have published a .htaccess trick to enable logging in from instead of

Their trick is perfectly valid, yet improvable: it requires editing of the .htaccess, a file you don't want noobs to mess with. So my thoughts were: "OK, that's nice and everything, but a simple plugin would be cleaner, easier for beginners, and more portable". Let's do this?
Read More

Every year, Christmas is a truly awesome event at my parents' with my sisters, wife and brothers-in-law. We offer each other a shitload of gifts while eating fine food cooked by Mom and drinking top notch wine prepared by Dad. In those dozens of gifts, of course a lot are mostly jokes or inexpensive stuff, and every year I make several DIY stuff that are funny and anticipated for.

Two years ago one of my presents was, for each couple, a little pack of "Love Coupons". I liked the cute sissiness of the idea but wanted to make it more funny and less sissy, so I scouted the web for Barbie and Ken pictures to make several cool coupons, such as these ones (in Fwench). Good for… a romantic night, a massage, kinky stuff, shopping with you, etc…, each time trying to more or less match the Barbie pic.

It was funny and girls loved it :) When I showed them to friends, several asked for the file so they could print the same, so here it is, in its full .PSD glory complete with 13 layers of different Barbie pics (and English messages).

Click to download the .psd (5.3 MB)

If you happen to use the PSD template and make some cool Love Coupons, be sure to share some pics :)

Wife and kids decorating our Christmas tree:

This is my first time lapse video. After having taken 150 pictures I decided it would be a good idea to read a few tutorials on how to make time lapse videos, and, well, it would have been slightly better the other way around :) The exposure is a bit short and the lightning should have been tweaked before shooting. I'm learning, and I definitely want to do more of this. I've just snatched an intervalometer on Ebay because, yes, I was sitting near the camera for all that time :)