Thibauld - Imagination and Execution -

2Oct/100

Get a command prompt with administrator privileges from explorer

RT @thibauld Get a command prompt with administrator privileges from explorer

While I was looking to install Dig on my Windows 7 machine. I stumbled on a dead simple but very useful piece of code that I thought I would share with you. It just allows you to open a command prompt as an administrator on any folder by doing a right mouse click on this folder.

  1. Download CmdHereAsAdmin.inf
  2. Right click on the file and choose "Install"
  3. You're all set!

You can now right click on any folder an launch an CMD prompt with administrator privileges directly from the explorer. Quick & easy!

24Sep/100

postgresql, date input format and black magic

RT @thibauld postgresql, date input format and black magic

I hate when I have the impression that black magic took the control of my PC. If you're a developer, you know it happens sometimes... when something is obviously wrong but you just can't figure out *what* is wrong. Hopefully, we work in IT, a field where we can reasonably assume that *everything* happens for a reason. So after digging a while, you eventually end up finding where the issue comes from.

It happened this week while trying to figure out why Postgresql had a different behavior on apparently completely similar platforms. I'm born April 1st, let's say I want to save my birthday in a table, I'd go with the following SQL statement :
INSERT INTO birthdays (date) VALUES ('01-04-1981');

As I'm french, each time I deal with dates, I tend to verify that they were understood correctly. Indeed, the above date format was french ('dd-mm-YYYY') but postgresql could have interpreted as a US date format ('mm-dd-YYY'). So let's check with the following statement:
SELECT date_part('month',date) FROM birthdays;

Here comes the problem. On 2 different machines with (apparently) the same setup, this statement would return 2 different results. One would return '04' (correct) and the other one would return '01' (wrong).

I took me a while to find out that postgresql had datestyle option (in postgresql.conf) which defines the rule to interpret ambiguous date input values.

So if datestyle is set to 'iso, dmy', it means dates will be interpreted as 'date-month-year' and if it is set to 'iso-mdy', dates will be interpreted as 'month-date-year'. It is that simple... once you found it :)

24Aug/101

How to validate email addresses in PHP

RT @thibauld How to validate email addresses in PHP

I guess that every PHP developer out there already had to cope with email validation in PHP. I personally used to think it was not completely straight forward.

Indeed, when you google the subject you quickly find this article with a completely misguiding title: "Validate an Email Address with PHP, the Right Way". Do not use the regexp proposed in this article outdated article. Not only because ereg() has been deprecated and replaced by preg_match() in latest PHP version (5.3 actually), but also because there is much simpler since PHP 5.2.

Check this out:

function is_email_valid($email) {
return filter_var($email,FILTER_VALIDATE_EMAIL)!==false;
}

Now, that's straight forward, isn't it? Here's filter_var() documentation if you want to find out more.

Tagged as: , , 1 Comment
15Feb/103

How to exclude multiple directories while creating an archive with tar

RT @thibauld How to exclude multiple directories while creating an archive with tar

A very quick post again as I've just spent way too much time to find out how to use the --exclude option of tar. All I wanted is tar to omit a few subdirectories while creating an archive of a directory. I was surprised to see how much tar is picky about his --exclude option: if you don't use the exact syntax, it won't work and, unfortunately, the exact syntax is not so easy to figure out from the man page.

So here is the exact syntax you should use if you want to exclude multiples directories with tar:

tar cvfz myproject.tgz --exclude='path/dir_to_exclude1' --exclude='path/dir_to_exclude2' myproject

Hope it will save you some time!

Tagged as: , , 3 Comments
15Feb/100

Moblin and Maemo projects are merging

RT @thibauld Moblin and Maemo projects are merging

Wow, just received this email from the Moblin mailing list. It announces the merge between Moblin (Intel initiated project) and Maemo (Nokia initiated project) :

Hi Everyone

I'm sure you've heard the news: Moblin and maemo are merging! We are taking the best pieces from these two open source projects and are creating the MeeGo software platform. Both teams have worked for a long time to support the needs of the mobile user experience - and MeeGo will make this even better. We want it to be fun, focused, flexible, technically challenging and ultimately, something that can change the world.

We all use mobile devices every day. The power and capability of handhelds has reached astounding levels - netbooks have been a runaway success - and connected TVs, tablets, in-vehicle infotainment, and media phones are fast growing new markets for devices with unheard of performance. Our goal is to develop the best software to go with those devices. The teams behind maemo and Moblin have plenty of experience and even more ideas on how to make things better - and together we will create something special.

So what does this mean for Moblin and its community? It's a huge opportunity. There are some changes (and those are always scary), but I think they are all for the better. Things will quickly shift to the new site, but from a technology point of view, migrations should be smooth. Especially if you are an application developer; everything you have done so far should continue to work - and with Qt and its development environment there are even more and easier options available to develop new and exciting apps for MeeGo.

The MeeGo website is still evolving - you'll run into a few "coming soon" pages as we pull all the content together and get things ready for our first project release in the second quarter. But there's already a lot to see - and a community to join! Please take a look - and come back often as we approach that first release.

We really want to hear from you. Be in on IRC, on our developer mailing list, or through bugzilla. MeeGo is an open project and it will be successful through its developer community. It's my personal goal to make sure that we can all together be successful. And have fun.

I invite you to join us at meego.com.

Imad Sousou

Director of Intel's Open Source Technology Center
(and now also co-chair of the MeeGo steering group)

From a business standpoint, it does make a lot of sense to merge these 2 projects, now let's see if the merge can be handled smoothly technically speaking... might not be as easy as it sounds.

5Feb/103

Configuring iptables to allow internet surfing while blocking all unsolicited incoming connexions

RT @thibauld Configuring iptables to allow internet surfing while blocking all unsolicited incoming connexions

I'm so used to connect to the Internet through network masquerading (NAT) that I was really surprised today when I realised that my laptop was actually receiving a lot of unsollicited connexions attempts from random external machines. Then I remembered that, by default, a freebox gives you a public ip !

It could not have been an issue if I was not doing web development on my laptop using a local (badly configured) webserver which happened to be worldwide accessible... oOops :)

A few iptables commands later, everything was secured :

iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -s 127.0.0.1 -j ACCEPT

The above lines configure iptables (the firewall) to drop every incoming connexions except the ones corresponding to a connexion I established with a remote server. Indeed, the server you're connecting to needs to be able to send information back to your machine in order for you to get it (blocking all incoming traffic is the same as unplugging the network connection).

I thought it might be useful to some of you too...

31Dec/090

Google real time search results

RT @thibauld Google real time search results

I've just noticed beautiful live search results integrated into google search results tonight. I had never seen them before so I thought I'd share this news-to-me with you :) Here's what I saw when I looked for "2010 resolutions" :

google_live_search_results

And then, a few seconds later, without refreshing anything on my side :

google_live_search_results1

I love it :)
Now let's go party for 2010!
Happy new year everybody!

8Dec/090

8th of December aka “The Longest Day”

RT @thibauld 8th of December aka “The Longest Day”

I don't why but, today, 8th of December, everybody decided that it was *the* day to make events and conferences. We had no event or such since a few month and then, suddenly, you have this crowded 8th of December. Today I would have love to attend :

  • The P'tits déjeuners de la science organised by my engineering school (INSA de Lyon) with Valérie Pécresse and Claudie Haigneré (french politics)
  • The Netbook World Summit organised by Mandriva with the presence of Scott Apeland, responsible for the Intel Software Network (read Application Store)
  • The World first Bizspark Camp organised by Microsoft with the presence of Scott Guthrie, Corporate Vice President de Microsoft Corp, .NET Developer Division
  • The Annuel meeting of G9+ with the following topic: "L'entreprise face aux Réseaux Sociaux" [quick translation: "Companies and Social Networks"] in the presence of Tara Hunt
  • The Life is better on party organised by OpenCoffee Paris before LeWeb
  • The Partners & Speakers reception for LeWeb'09 organised by Loïc & Géraldine

Now this is really great but please, next time, let's try to spread that a little over a few days so that I do not have to choose between the events :)

7Dec/090

Allmyapps 4 slides pitch for OpenCoffe Paris before LeWeb

RT @thibauld Allmyapps 4 slides pitch for OpenCoffe Paris before LeWeb

opencoffee

It's been sooo long since I blogged! The thing is that the activity at Allmyapps is just exploding (a good problem to deal with!) and unless days suddenly get bigger (say 48h a day), there's no way I can keep up-to-date with my todo list. Task prioritization is the keyword right now at Allmyapps :)

However, I really *want* to write more blog posts... so I'll try to make a bit smaller while keeping their interestingness high. Let's begin now and see if I can manage that in the long run.

Today, I just wanted to share with you the 4 slides we've proposed to pitch Allmyapps at the OpenCoffee Paris which is taking place right before LeWeb09.



I hope we'll be selected to pitch! [Edit: We've been selected to pitch!]

17Jul/091

PHP function to draw nice looking XY plot charts with google chart API

RT @thibauld PHP function to draw nice looking XY plot charts with google chart API

Creating nice charts used to be a hard task. Lately, I dug a little bit into Google chart API to see what they had to offer and how they could help me draw nice looking charts easily.

In theory, using Google chart is dead simple: just build an URL with the right parameters and Google will return you an image with your nice looking chart. However, in practice, it turned out a little bit more tricky. If you only want to draw a pie charts then it is pretty straight forward. But if you want to build an XY plot chart, then it gets harder!

Indeed, you should not use Google chart API like you'd use a spreadsheet. Keep in mind that Google chart API is about drawing an image: the X axis and the Y axis are treated completely independantly of your points coordinates.  If you do not pay enough attention, you'll end up with a chart with a completely wrong scale.

I tried to find some PHP libraries to help me draw my XY chart but found nothing satisfactory, so I finally decided to write my own little PHP function. Let me share it with you:

function getChart($chart) {
$y_max = $chart['y_max'];
$y_min = $chart['y_min'];
$y_step = $chart['y_step'];
$y_grid_step = $chart['y_grid_step'];
$x_max = $chart['x_max'];
$x_min = $chart['x_min'];
$chart_size = $chart['chart_size'];
$title = $chart['title'];
$x = $chart['x_axis'];
$x_nb = count($x);
$x_int = 100/$x_nb;
$first = 0;
if ($chart['x_labels_centered']) $first = $x_int/2;
for($i=0;$i<=$x_nb-1;$i++) { $positions[] = floor($first + ($i * $x_int)); }
foreach($positions as $n => $pos) { $x_values[$pos] = $x[$n]; }
$x_range = implode(',',array_keys($x_values));
$x_labels = implode('|',$x);
$grid_step = $y_grid_step*100/$y_max;
$url = "http://chart.apis.google.com/chart?";
$cht = "cht=lc";
if (!empty($chart['data_y'])) $cht="cht=lxy";
$chd = "chd=t:".implode(',',$chart['data']);
if (!empty($chart['data_y'])) $chd.="|".implode(',',$chart['data_y']);
$chg = "chg=$x_int,$grid_step,1,5";
$chxt = "chxt=x,y";
$tmp = array();
for ($i=0;$i<=$y_max;$i+=$y_step) { $tmp[] = $i; }
$y_labels = implode(',',$tmp);
$chxp = "chxp=0,".$x_range."|1,".$y_labels;
$y_labels = implode('|',$tmp);
$chxl = "chxl=0:|".$x_labels."|1:|".$y_labels;
$chxr = "chxr=1,$y_min,$y_max,$y_step";
$chtt="chtt=".str_replace(' ','+',$title);
$chs = "chs=".$chart_size;
$chds = "chds=$y_min,$y_max";
$chm="chco=0000FFFF&chm=B,76A4FB,0,0,0";#|s,0000FF,0,-1,10";
if (!empty($chart['data_y'])) $chds ="chds=$x_min,$x_max,$y_min,$y_max";
$url .= implode('&', array($cht,$chd,$chg,$chm,$chxt,$chxl,$chxp,$chxr,$chtt,$chs,$chds));
return $url;
}

Dont' get me wrong: this is really a quick and dirty function and not meant to be beautiful code. Here is an invokation example:

$data_x = array(0,4,5,9,10);
$data_y = array(20,5,7,9,10);
$months_x = array('Jan','Fev','Mar','Avr','May');
$chart_xy = array(
'title'=>"Chart Title", // CHART TITLE
'data'=>$data_x, // CHART DATA (X)
'data_y'=>$data_y, // CHART DATA (Y)
'x_axis'=>$months_x, // X AXIS LABELS LIST
'x_labels_centered'=>true, // SHOULD LABELS ON X AXIS BE CENTERED?
'y_min'=>0, // MIN VALUE OF Y AXIS
'y_max'=>25, // MAX VALUE OF Y AXIS
'y_step'=>5, // Y AXIS INTERVAL (NUMBERS ON THE AXIS)
'y_grid_step'=>5, // Y AXIS GRID INTERVAL (HORIZONTAL LINES ON THE GRID)
'x_min'=>0, // MIN VALUE OF X AXIS
'x_max'=>10, // MAX VALUE OF X AXIS
'chart_size'=>'300x300' // CHART DIMENSIONS
);
$url = getChart($chart_xy);

This code would result in the following graph:

And if I change :

$months_x = array('Jan','Fev','Mar','Avr','May');

by

$months_x = array('Jan','Fev','Mar');

I get the following graph:

What is important to note here is that it is up to you to make your X and Y axis consistent with your data, ortherwise, you'll end up with a totally meaningless chart.

Of course, this code is adapted to my needs so please feel free to copy this PHP function and adapt it so that it fits your particular needs!

Hope it will be useful for some of you...