Guttulous L∞ps

implementing Undegeekable

Cubik Architecture

Responds to size, orientation, fullscreen or windowed image swiping.

Crafted with pleasure and designer Joffrey Jochum.

Cubik Architecture

PHP ~ Rooted Tree Node Serialization

UPDATE : That was before I found out about SPL’s Recursive Tree Iterator. Well, live and learn !


I wrote a Symfony2 bundle providing tools for easy (de)serialization of rooted trees structures where nodes hold a string value, and some methods for tree handling.

Using this, I can easily generate random trees like :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
A
+--B
|  +--C
|  |  +--D
|  |     +--E
|  |     |  +--H
|  |     |  +--I
|  |     +--R
|  |     +--T
|  +--F
|  |  +--J
|  |  |  +--M
|  |  |  |  +--N
|  |  |  |  |  +--P
|  |  |  |  +--Q
|  |  |  |  +--U
|  |  |  |     +--V
|  |  |  +--Y
|  |  +--L
|  |     +--O
|  |        +--X
|  |        +--Z
|  +--G
|     +--W
+--K
   +--S

It is extensively tested but it has a small learning curve, if you’re new to Symfony.

Code Completion for PHPUnit_Framework_TestCase in PHPStorm

To allow PHPStorm to discover the PHPUnit classes, go to Settings > Project Settings > PHP, and add the path to PHPUnit, usually something like /usr/share/php/PHPUnit.

Now you do not have an excuse not to test your Symfony2 bundles !

Doodle Away !

I experimented a bit with canvas and paper.js, and made an online doodle app working quite nicely on powerful tablets.

You can fork the whole project on github.

The trick was to have two separate canvases, one for the path being drawn, and the other for the paths already drawn. PaperScript’s tricky clever scoping is inspiring — my usage of it feels like a hack.

Remember to press C for Free Cake© once you’ve drawn some lines !

Elfassy Barrès Associés

Very light, very fast, highly responsive, generated using Phrozn.

Crafted with pleasure and designer Joffrey Jochum.

Screenshot of EB website

Review the A-grade benchmark.

TODO

  • Minify mootools libs
  • What happened to the favicon ?

PHP ~ Slugify a String With or Without Iconv

While playing with Symfony (with Doctrine), I twaeked some of their built-in functions that I found useful. Slugifying a string for instance, for when you want pretty URIs…

Without iconv

What if my server has not iconv ?

Here is how to quickly slugify a string without iconv. Try the following function, which covers less use-cases, but enough sometimes.

Slugify an UTF-8 string using vanilla PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
/**
 * Returns the slugified (aka urlized) $string,
 * which will match \a-z0-9-\
 * Some special chars are
 *
 * "Ça alors, déjà !?" => "ca-alors-deja"
 *               "Œuf" => "uf"   :(
 *          "~&a; -b?" => "a-b"
 *             "! ? #" => "n-a"
 *
 * Notes :
 * - $string must be UTF-8
 * - æœÆŒ not covered !
 *
 * @param  string $s The utf8 string to slugify
 * @return string    The slugified string
 */
function utf8_slugify ($s) {
  $s = utf8_decode($s);
  $s = html_entity_decode($s);

  // list is not extensive -- suggestions are welcome !
  $b = 'ÀÁÂÃÄÅàáâãäåÇçÈÉÊËèéêëÌÍÎÏìíîïÑñÒÓÔÕÖØòóôõöøÙÚÛÜùúûüÿ';
  $a = 'AAAAAAaaaaaaCcEEEEeeeeIIIIiiiiNnOOOOOOooooooUUUUuuuuy';
  $s = strtr($s, utf8_decode($b), $a);
  $s = trim($s); // trim white whars

  // remove unwanted chars
  $s = preg_replace('/([^a-z0-9]+)/i', '-', $s);
  $s = strtolower($s);

  // remove `-` duplicates
  $s = preg_replace('/--+/', '-', $s);
  $s = trim($s, '-'); // trim `-`

  if (empty($s)) return 'n-a';

  return utf8_encode($s);
}

This is a hack as-is, neither maintained nor properly unit tested. Nowadays, I recommend using Inflectors instead of this function.