Forex for beginners

Posted on May 19, 2011

Today, I’m taking the time to talk about my new project, It’s a website (in french only so far) whose aim is to teach Forex to very beginners, in a way it has not been done before. We really make Forex easy to learn for beginners, who can really start from the very beginning and end by reaching a good level in Forex trading. Our core business is divided into 3 main sectors.


Change Chrome search default language

Posted on December 7, 2010

The last day, I was given a brand new MacBook Pro at my new job. First thing to do: open Safari … in order to download Chrome! But I don’t know why (some traces of French settings?), the default search engine for Chrome was (french language), and not (english language). Impossible to change it in the list of search engines, and there was this google:baseurl setting (set to that I couldn’t overwrite. No way until I found the solution below.

Stop Chrome.

Open the following file (on Mac OS X, files is located elsewhere for Linux and Windows users):

vim ~/Library/Application\ Support/Google/Chrome/Local\ State

And look for the three following lines:

"StartupDNSPrefetchList": [ 1, "" ]
"last_known_google_url": ""
"last_prompted_google_url": ""

There, change the URL by the one you want (in my case I turned in

Restart Chrome.

The default language for google should be english now. At least, it worked for me 🙂

Minimize windows into application icon

Posted on December 2, 2010

I’ve just discovered this feature in Snow Leopard and it’s changing my life. It allows me to reduce a window into the application icon (in my dock), instead of going to the right of the dock next to the trash bin. I’m really happy of that feature especially because I’m keeping the MAMP window up every time, and I didn’t like to waste space in my dock for that!

To activate this feature, go to System Preferences, then to Dock, and check the box called Minimize windows into application icon. From now on, your windows will reduce and not take more space into the dock.

Screenshot of the dock preferences in Snow Leopard

Rotating your log files with logrotate

Posted on November 2, 2010

If you’re like me and you’re used to log what’s going on your web application, you might want to know how to rotate your log files just like Linux commonly does for its system logs. No need to code anything for that purpose, you can simply use the same software as your system: logrotate.

Attention: I wrote this post based on my personal server which is a Linux Debian 5.0 Lenny and logrotate 3.7.1, but it’s very likely that it works more or less the same way for any Linux server and version of logrotate.

When installing logrotate, it’s likely that it’s already designed to rotate some system logs (syslog, kern.log …), and in the case of a web server, it also rotates Apache or MySQL (access.log, error.log, mysql.log…). Having a quick look at the manual (#man logrotate), you’ll see you can easily tell logrotate to handle your own log files. Simply open /etc/logrotate.conf (or touch a new file in /etc/logrotate.d/ if it exists for your version), and add something like the following:
"/home/mysite/log/visitors.log" "/home/mysite/log/downloads.log" {
rotate 5
size 100k
/usr/bin/killall -HUP httpd

This example section will handle both visitors.log and downloads.log (you can add as many file locations as you wish). The options are:
  • rotate 5: it means it will rotate 5 times before deleting data
  • mail will send an email with the content of the latest log file before deleting it
  • size 100k: maximum size for a log file before rotating it
  • postrotate […] endscript: enclosed is a piece of script you want to be run after rotating logs
  • nocompress: add this line to prevent logrotate from compressing rotated log files

These are the main options for logrotate, but of course many others can be found, please read the manual for more.

And there you are, your custom log files are being rotated without having to code a custom PHP script 🙂

Proposal: best practices for writing PHP

Posted on October 3, 2010

My motivation in writing this proposal comes from years of PHP practice, when I had to use other people’s code and their code looks like garbage so much that I wanted to throw it to the their face rather than using it. I can’t expect everybody to write clear code, but if I could turn the actual world in a world of beauty and smartness, I’d like people to follow the guidelines in this paper. Note that I didn’t pretend to write complete PHP good practices, as I’m just covering the writing aspect of PHP coding, with concerns such as readability and logic in the flow of code.

Good practices for PHP writing

strtolower and UTF-8

Posted on September 27, 2010
Charset issues is something that always made me go mad. And since I’m french and I’ve designed many french websites, it’s something I couldn’t escape, thanks to all these special chars we have in our language 🙂

Well, today an issue came up with the strtolower function. Look at what follows:

$t1 = 'Expérience';
$t2 = strtolower($t1);
echo $t2; // echos 'expience'

See? It drops the two letters “ér”. No matter why and how it processes (for more details about UTF-8/ISO issues, please use google), what matters is that it totally screwed up my beautiful string.

On, you can read this function uses the charset defined in the current locale. It means that whatever the encodage of your string is (UTF-8, ISO, …), even if you work with UTF-8 all along (database tables, database connection, page chars …), it will use the current locale charset anyway.

To this, I can see two options.

Suexec behaviour with nginx

Posted on September 5, 2010

This week, I had to set up and configure an nginx server for the first time. If there is something that I think is essential for a web server, it’s to clearly separate the environment of each of the websites that run on it. Especially, when you execute PHP (or whatever) scripts on your website, security is something you have to pay attention to.

Sort an ArrayCollection in Flex

Posted on August 12, 2010

As nothing’s as straight forward as PHP, I had to write my own class to sort ArrayCollections. My work was inspired by what Peter Dehaan did.

The method is to be used as follows:

ArrayUtils.sort(games, "playerScore", "DESC", true);

to sort an ArrayCollection of games by player score, with a descending order. The last parameter indicates that we want a numeric sorting rather than a alphabetical sorting.

I encapsulated the method in an ArrayUtils class, but you’re free to do as you wish. That’s because I think I will add more methods to my class in a near future. You can download the class here:

package classes.utils
import mx.collections.ArrayCollection;
import mx.collections.Sort;
import mx.collections.SortField;
* Useful functions to manipulate arrays
* @author Cyril Mazur
public class ArrayUtils
* Sort an arrayCollection by key
* order MUST be either "ASC" or "DESC"
* @author Cyril Mazur
* @see
* @param ArrayCollection arrayCollection
* @param String sortBy
* @param String order
* @param Boolean numericSort
* @return ArrayCollection
public static function sort(arrayCollection:ArrayCollection, sortBy:String,
order:String, numericSort:Boolean):ArrayCollection {
/* Create the sort field and fill it */
var dataSortField:SortField = new SortField(); = sortBy;
dataSortField.caseInsensitive = true;
dataSortField.numeric = numericSort;
/* Set the order, by default it's ascending */
if (order.toUpperCase() == "DESC") {
dataSortField.descending = true;
/* Create the Sort object and add the SortField object
created earlier to the array of fields to sort on. */
var dataSort:Sort = new Sort();
dataSort.fields = [dataSortField];
/* Set the ArrayCollection object's sort property to our
custom sort, and refresh the ArrayCollection. */
arrayCollection.sort = dataSort;
/* Return the collection */
return arrayCollection;

Download the source here:

I’m open to any suggestion to improve the code 🙂

getDefinitionByName(), ReferenceError: Error #1065: Variable is not defined

Posted on August 8, 2010

In Flex (as in Java, or even PHP) you can dynamically get references to a class from its name. Just to remind you, it’s that easy in PHP:

$className = 'User';
$myUser = new $className;

Not a lot more complicated in Java:

Class className = Class.forName("User");
Object myUser = className.newInstance();

The Flex way is as follows:

var className:Class = getDefinitionByName("package.User") as Class;
var user:Object = new className();

But despite PHP and Java, there is a little subtlety for Flex. You can encounter the following error when executing this code:

ReferenceError: Error #1065: Variable User is not defined

And it took some time for me to figure out what the problem was… After looking at the right speling of my class name and so worth, I figured out that the problem comes from the way that Flex compiles its code. Actually, Flex compiles its code so that if a class is not used, it will keep this class off the final compiled program. And even a

import package.User

won’t change a thing. The only way to get it done, is to put a reference to that class somewhere in your code, wherever … as long as it’s referenced somewhere, Flex will not forget the class at the compilation process. A simple and ugly way is to add a dummy reference to this class somewhere, like:

private var _dummyUser:User;

or shorter:


and you’re done.

It has been already discussed on forums and blogs, but as I came across this I had to write an article about it 🙂

Unique ID for Java classes

Posted on August 5, 2010

As I was writing some Java code for my finale dissertation, I wanted to give my objects an unique ID in order to distinguish them easily. I thus wrote the following abstract class that does the job well for me:

package motd.utils;
* Makes a class identifiable with an unique ID for its objects
* @author Cyril Mazur
abstract public class Identifiable {
  * The object's ID
  protected int id;
  * Constructor
  public Identifiable() { = getNextId();
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  public int getId() {
    return id;
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  * Index for the object's ID
  protected static int index = 0;
  * Return next ID
  * @return int
  protected static int getNextId() {
    return ++index;

Download here

Make your class to extend Identifiable, don’t forget to call the super() constructor, and you’re done.

Now, all of your objects will have an ID attribute which will identify them in a unique way. Of course this attribute is private, and I’ve added a getter for it, since it’s a good OOP practice.

Note 1: with my class, the counter is global. It means that when the counter increments, it increments for all the classes that extend Identifiable in your program. Two objects of different classes will never have the same ID. I don’t know if it’s wrong or if it’s right in the end… If someone has an idea on how to make the counter dedicated to each class, feel free to leave a comment 🙂

Note 2: I’m far from being a god of Java, and it’s likely that my tip is just for beginners who don’t use frameworks that would already encapsulate this feature