Bière Ommegang


Au début je n’y ai cru qu’a moitié. Puis j’ai oublié…
Il y a quelques jours j’ai reçu un mail pour me dire que le brassin était pret et que dès que l’embouteillage aurait lieu, la bouteille serait envoyée.
Là je me suis dit: “ça doit être une erreur, ils ont envoyé un mail à tout le monde alors qu’ils ne ciblait que les acheteurs”.
Mais, je dois me rendre à l’évidence, car c’est bien arrivé. Aujourd’hui j’ai été chercher au point poste ma bouteille d’Ommegang édition limitée.
Waw… ça c’est du marketing!
Pas de spam, un message pour dire que ça va arriver et puis le cadeau. Propre, simple efficace.
Bon, il ne reste plus qu’à gouter.

Calling XmlRpc of WordPress with Zend Framework (Zend_XmlRpc_Client) and adding the default thumbnail to a post

This code is in 2 parts

First part, we download an image somewhere using Zend_Http_Client

Second part, we use xmlrpc to upload the image into wordpress as a media and to create a post using this media as featured image or default image of main thumbnail, whatever the name is

Let’s have a look at the first part:
Downloading an image with Zend_Http_Client
this is quite simple

				require_once 'Zend/Http/Client.php';
				$config=array(
					'adapter'=>'Zend_Http_Client_Adapter_Curl'
				);
				$Zend_Http_Client = new Zend_Http_Client($imageUrl,$config);
				try{
					$result = $Zend_Http_Client->request('GET');
				}catch(Exception $e){
					print_r($e);
				}
				$data = $result->getBody();
				//file_put_contents('/tmp/test.jpg',$data); // this is just to test the image if you are unsure

second part, storing the image in wordpress and creating a post with custom field: _thumbnail_id set to this image

To store a media object we will use the metaWeblog.newMediaObject XmlRpc method

				require_once 'Zend/XmlRpc/Client.php';
				require_once 'Zend/XmlRpc/Value/Base64.php';
				require_once 'Zend/XmlRpc/Value/Struct.php';
				require_once 'Zend/XmlRpc/Value/Array.php';
				$xmlRpcClient = new Zend_XmlRpc_Client('http://www.example.com/myblog/xmlrpc.php');
				try{
					$thumbnail = $xmlRpcClient->call(
						'metaWeblog.newMediaObject',
						array(0,
							'login',
							'pass',
							array(
								'name'=>'test.jpg',
								'type'=>'image/jpeg',
								'bits'=>new Zend_XmlRpc_Value_Base64($data),
							)
						)
					);
// ...

in the thumbnail object we don’t get the id… because it’s not possible to get the id unless you hack wordpress

WP file: wp-include/class-wp-xml-rpc.php

method: function mw_newMediaObject($args) {

modification: add the id in the return:

return apply_filters(
	'wp_handle_upload',
	array( 'file' => $name, 'url' => $upload[ 'url' ], 'type' => $type )
	, 'upload'
	);

by:

return apply_filters(
	'wp_handle_upload',
	array( 'file' => $name, 'url' => $upload[ 'url' ], 'type' => $type, 'id'=>$id )
	, 'upload'
	);
// ...
		$struct = new Zend_XmlRpc_Value_Struct(
					array('key'=>'_thumbnail_id', 'value'=>$thumbnail['id'])
				);
		$result = $xmlRpcClient->call(
			'metaWeblog.newPost',
			array(0,
			'login',
			'pass',
			array(
				'post_type'=>'post',
				'title'=>'New article with thumb',
				'description'=>'Article text',
				'custom_fields'=>array($struct),
			),
			false)
		);
	}catch(Exception $e){
		print_r($e);
	}

Of course, this won’t work… because no one is allowed to access private custom_fields such as _thumbnail_id …

A second WP hack is necessary here:

file: wp-includes/meta.php
function: is_protected_meta

add an exception for _thumbnail_id

function is_protected_meta( $meta_key, $meta_type = null ) {
        if($meta_key == '_thumbnail_id'){
                $protected=false;
        }else{
                $protected = (  '_' == $meta_key[0] );
        }
        return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type );
}

Without a nice documentation that was the best I could do in few time.

Another approach could be to create a new XmlRpc method, which do both in once avoiding the weakness of reusing an internal id in a second call, but still XmlRpc use add_meta which is a really ugly way to add meta in a post as everything has to be put in $_POST …

If anyone has a better approach (using xmlrpc) feel free to submit the suggestion.

A third approach could be to write a plugin… that’s next step

All the assumption I want to remember in PHP

Probably linked to some alcohol I drank to young, I always forget some key assumption in PHP.

NULL is NULL
NULL is EMPTY
NULL is FALSE
NULL has a sizeof 0

BUT

FALSE is not NULL
FALSE is EMPTY
FALSE is FALSE
FALSE has a sizeof 1

AND

empty ARRAY is not NULL
empty ARRAY is EMPTY
empty ARRAY is FALSE
empty ARRAY has a sizeof 0

$test=NULL;
if(is_null($test)){print("NULL is NULL");}else{print("NULL is not NULL");}
// NULL is NULL
if(empty($test)){print("NULL is EMPTY");}else{print("NULL is not EMPTY");}
// NULL is empty
if($test){print("NULL is TRUE");}else{print("NULL is FALSE");}
// NULL is FALSE
print(count($test));
// 0
$test=false;
if(is_null($test)){print("FALSE is NULL");}else{print("FALSE is not NULL");}
// FALSE is not NULL
if(empty($test)){print("FALSE is EMPTY");}else{print("FALSE is not EMPTY");}
// FALSE is EMPTY
if($test){print("FALSE is TRUE");}else{print("FALSE is FALSE");}
// FALSE is FALSE
print(count($test));
// 1
$test=array();
if(is_null($test)){print("empty ARRAY is NULL");}else{print("empty ARRAY is not NULL");}
// empty ARRAY is not NULL
if(empty($test)){print("empty ARRAY is EMPTY");}else{print("empty ARRAY is not EMPTY");}
// empty ARRAY is EMPTY
if($test){print("empty ARRAY is TRUE");}else{print("empty ARRAY is FALSE");}
// empty ARRAY is FALSE

Run 20km and give them water

Run and Give them waterAvec 425 autres coureurs nous allons nous lancer dans la course afin de récolter 30 000 € pour le croix-rouge.

Run and Give them water est un projet d’approvisionnement en eau potable au Rwanda

Pour faire un don: suivez le lien: http://www.croix-rouge.be/20km/parrainage_don.htm et rajouter SEBASTIEN BARBIERI à la fin de la zone d’édition.

20 KM PARRAINAGE – SEBASTIEN BARBIERI

Ou faites un versemment au compte: 000-0000016-16 avec la mention “20 KM PARRAINAGE + SEBASTIEN BARBIERI”

Pour me parrainer vous pouvez décider par exemple de donner 50 cents/km, et pour chaque kilomètres que je parcours, vous versez 50 cents soit 10€ pour les 20km.

Je m’engage pour ma part à courir pour 5€/Km => 100€.

Soutenez-moi, par vos encouragement ou par un don.

baladodiffusion

Adieu podcasts, bienvenue Baladodiffusion!

Quel est le principe?

La radio propose sur un site des liens vers des fichiers audio permettant de réécouter une émission radio de manière diférrée.

Avantages

Pouvoir écouter quand on veut et où l’on veut une émission.

Bon mais c’est la même chose que le podcast jusque là. Alors quel est la différence ?

La différence est déjà dans le mot BALADO-DIFFUSION, la diffusion en balade.
Balade: Selon le wiktionnaire:

Etymologie: Du verbe balader, lui-même venant de ballade (« poème chanté ») en raison des saltimbanques qui se déplaçaient sans destination particulière et qui chantaient des ballades pour demander l’aumône.

C’est ici toute l’idée: Balade, poème chanté, déplacement, mobilité. A notre époque il s’agit de pouvoir se promener avec de la musique. Totalement différent de Podcast, qui n’est qu’un mot commercial contraction de iPod(R) et de broadcast ==> diffusion sur iPod…

WTF?

Oui, je sais…

Faites comme moi, adieu podcast, bienvenue baladodiffusion et m…. à l’envahisseur (Pomme (R) )

TAG: #baladodiffusion #jeBosseSurMusiq3 #vivelamusiqueclassique

Open Dojo v1.0

Subject list for an open dojo / bbq session

As Jedi

  • phpunit and code coverage
  • phing deployment
  • svn and continuous integration

As Padawan

  • Working agile
  • Scrum

Now let’s decide a timeline

Couteau “Chef” Evercut

Ca y est!

J’ai reçu mon couteau Evercut!

Couteau Chef Evercut


Terrible packaging!

Ultra sharp, il coupe super bien.

Pour l’instant je n’ai testé que quelques légumes (oignons, échalotes, courgettes) mais c’est vraiment nickel.
Une très grand précision pour les petits détails.

En plus il fait un bruit terrible quand il coupe… j’adore. C’est mon auto-cadeau de Noël !!!

From Evercut

Le site du couteau: http://www.evercut.fr/ – Le concepteur: http://www.tb-groupe.fr/

Continuous Integration phpunit code coverage use a bit less than 2 Gigs !!!

2 gigs !!! gasp

I had several:

Generating code coverage report, this may take a moment.PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 21503527 bytes) in /usr/share/php/PHPUnit/Util/Report/Node/File.php on line 406

And here is how it started:

At work we are using phpunit to test our framework, we flew from SimpleTest as there was no real integration with our tools and no real followup of the the product.

So to automate the test, as there is no “build” in php (interpreted vs compiled remember?) we ran it after each commit …

Until it tooks 30 minutes to run throught the whole set of tests…

Continue reading Continuous Integration phpunit code coverage use a bit less than 2 Gigs !!!

installing xdebug on ubuntu with Zend Server CE (not solved yet)

You need to sudo

user@laptop:~$ sudo bash

1st be sre to have the pecl, pear available as root in command line

root@laptop:~# PATH=$PATH:/usr/local/zend/bin

trying to install

root@laptop:~# pecl install xdebug
downloading xdebug-2.1.0.tgz ...
Starting to download xdebug-2.1.0.tgz (301,354 bytes)
.....................................................done: 301,354 bytes
66 source files, building
running: phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

ERROR: `phpize' failed

Argl it seems to be failing…

looks like autoconf is missing

root@laptop:~# autoconf
The program 'autoconf' can be found in the following packages:
* autoconf
* autoconf2.13
Try: apt-get install <selected package>

ok let’s add it:


root@laptop:~# apt-get install autoconf

and now let’s try again


root@laptop:~# pecl install xdebug
downloading xdebug-2.1.0.tgz ...
Starting to download xdebug-2.1.0.tgz (301,354 bytes)
.............................................................done: 301,354 bytes
66 source files, building
running: phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
configure.in:3: warning: prefer named diversions
configure.in:3: warning: prefer named diversions
building in /var/tmp/pear-build-root/xdebug-2.1.0
running: /tmp/pear/temp/xdebug/configure
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
...
Build process completed successfully
Installing '/usr/local/zend/lib/php_extensions/xdebug.so'
install ok: channel://pecl.php.net/xdebug-2.1.0
configuration option "php_ini" is not set to php.ini location
You should add "extension=xdebug.so" to php.ini

Great!

Don’t forget to add the librairy in the php.ini

create the xdebug.ini in the ext.d directory and the symlink in the conf.d directory


root@laptop:/usr/local/zend/etc/ext.d# more xdebug.ini
zend_extension=/usr/local/zend/lib/php_extensions/xdebug.so
; You may put any extension-specific directives here

root@laptop:/usr/local/zend/etc/conf.d# ln -s ../ext.d/xdebug.ini xdebug.ini

Now let’s try PHP:

scips@laptop:~$ php
Segmentation fault

Looks like I need to investigate deeper…

Ok problem solved:

Instructions

Warning: You seem to be using Zend Server, which is known to cause issues with Xdebug. It might work, but you’re on your own.

Download xdebug-2.1.0.tgz
Unpack the downloaded file with tar -xvzf xdebug-2.1.0.tgz
Run: cd xdebug-2.1.0
Run: phpize

As part of its output it should show:

Configuring for:

Zend Module Api No: 20060613
Zend Extension Api No: 220060519
If it does not, you are using the wrong phpize. Please follow this FAQ entry and skip the next step.

Run: ./configure
Run: make
Run: cp modules/xdebug.so /usr/local/zend/lib/php_extensions
Open /usr/local/zend/etc/conf.d/debugger.ini and put a ; in front of the line that says zend_extension_manager.dir.debugger= so that it says ;zend_extension_manager.dir.debugger=
Edit /usr/local/zend/etc/php.ini and add at the begining of the file the line
zend_extension = /usr/local/zend/lib/php_extensions/xdebug.so

I did just paste in has requested my php -i output on http://xdebug.org/find-binary.php then compiled and everything ran fine.

The problem is that you have to use one or the other not the both at the same time… still not a real option for me.

Subversion backup & restore

Get it

first of all you need the best script ever made to backup subversion: the one provided with!

Get it here: http://svn.apache.org/repos/asf/subversion/trunk/tools/backup/hot-backup.py.in

This script needs to be modified

replace:


# Path to svnlook utility
svnlook = r"@SVN_BINDIR@/svnlook"
# Path to svnadmin utility
svnadmin = r"@SVN_BINDIR@/svnadmin"

with:


# Path to svnlook utility
svnlook = r"/usr/bin/svnlook"
# Path to svnadmin utility
svnadmin = r"/usr/bin/svnadmin"

or your appropriate svnlook and svnadmin path

Then you need to check that your user can modify files

once it’s verified let’s create a repository to store backup ‘/backup’ for instance and create your directory structure there

Test it

test the whole stuff

./hot-backup.py --archive-type=bz2 --num-backups=45 /svn/TEST_REPO/ /backup/subversion/test_repo/

you should get something like TEST_REPO-2.tar.bz2 (here minus 2 means revision n°2)

Schedule it

If you want to run it daily, put it in a cron such as a daily job

As I have multiple repositories here is my script


#!/bin/bash
NUMBACKUP=15
for i in `ls /svn/`
do
mkdir -p /backup/svn/$i
./hot-backup.py --archive-type=bz2 --num-backups=$NUMBACKUP /svn/$i /backup/svn/$i
done

Restore it

Ok that’s nice, you got a backup, but unless you can restore it, it’s useless!

So here is how to restore it:

  1. tar -xjvf /backup/svn/TEST/test-2.tar.bz2
  2. cp -R /backup/svn/TEST/TEST-2/ /svn/TEST/

and… that’s it

of course at the end of your backup script I recommend to move everything to another computer, because you will probably need it when disk crashes ;-)