When the studies end…

No Comments

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes)

There we are, the very end of my studies. I just handed out my finale dissertation on friday right on the dead line time (touch down on the responsible’s desk). And now guess what, I’m going to find a job in order to enrich my enterprise experience. HR guys, if you read these lines, you will find my résumé right here :)

There are a few things I have to do now (and yes, I announce them in advance, I’m not like Steve Jobs):

  1. redesign my blog
  2. update my résumé
  3. write a URL shortener (don’t ask why, I just want to do it)
  4. and finally be ready to hunt a job

My preference goes for London, because I really want to strengthen my english skills and have experience in english or international companies. But I’m totally open for another location, even in France if I’m ever offered a golden job.

You’ll be told about goal number 1 very soon as I’m currently working on it, I think it’ll be OK next week, defo.

Sort an ArrayCollection in Flex

No Comments

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes)

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: ArrayUtils.as

package classes.utils
{
import mx.collections.ArrayCollection;
import mx.collections.Sort;
import mx.collections.SortField;
 
/**
* Useful functions to manipulate arrays
*
* @author Cyril Mazur www.cyrilmazur.com
*/
public class ArrayUtils
{
/**
* Sort an arrayCollection by key
* order MUST be either "ASC" or "DESC"
*
* @author Cyril Mazur www.cyrilmazur.com
* @see http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/
*
* @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();
dataSortField.name = 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;
arrayCollection.refresh();
 
/* Return the collection */
return arrayCollection;
}
}
}

Download the source here: ArrayUtils.as

I’m open to any suggestion to improve the code :-)

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

No Comments

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes)

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:

User;

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

No Comments

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes)

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 www.cyrilmazur.com
*/
abstract public class Identifiable {
 
  /**
  * The object's ID
  */
  protected int id;
 
  /**
  * Constructor
  */
  public Identifiable() {
    this.id = getNextId();
  }
 
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  // GETTERS AND SETTERS
 
  public int getId() {
    return id;
  }
 
  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  // STATIC
 
  /**
  * Index for the object's ID
  */
  protected static int index = 0;
 
  /**
  * Return next ID
  * @return int
  */
  protected static int getNextId() {
    return ++index;
  }
}

Download Identifiable.java 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

onChange and checkbox/radio in IE

No Comments

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes)

I was writing a bit of Javascript this afternoon. Everything was fine until it came to test it on IE, and there the nightmare began (again, and again, and again…). Yes, IE (all versions) sucks at handling onChange events for checkboxes and radio buttons. Sometimes it works, sometimes not at all, sometimes you gotta click somewhere else in the page to trigger it…

I’ve made some researches on the Internet, and there is no beautiful way to fix that. The only way is to totally give up onChange events for those two elements (yes, you HAVE to give up a very regular feature just because ONE browser doesn’t support it properly), and to replace it by an onClick event. You’ll then hope that your code doesn’t change the values of your checkboxes in another way than by clicking on it, otherwise you’re fucked. Or you have to call the related onClick function every time.

Let’s see for example the case when you use an HTML label element for your input:

<input type="checkbox" onclick="someFunction();" id="myCheckbox" />
 
<label
  for="myCheckbox"
  onclick="document.getElementById(this.for).onclick();"
>
    Check me
</label>

I just had to change that in my case hopefully.

How I managed to get a 100eur + 8eur/month discount for my iPhone 4 at Orange

1 Comment

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes)

Big news: I moved to France recently. Ok I needed a phone, but I could have found cheaper than the new iPhone 4 (and I’m even not talking about the mobile contracts in France, it’s like stealth!). But no choice, I’m defo an Apple fan boy, and my current 3GS is alright to me, so I gave in to temptation: I just ordered a new iPhone 4 at Orange!

How I managed to get a 100 euros cash + 8 euros/month discount for my iPhone 4 at Orange

This is the deal I got, tell me if you could find cheaper in France for that:

  1. I chose the iPhone 4 16G, that costs 249 euros with the following contract: 50.90euros a month, for 2h + 2h nights and weekends, duration 24 months
  2. I got a 100 euros discount on my first bills because I ported an old SFR number (another french operator), and so I keep my former french number which is a good thing furthermore :)
  3. I got a 3euros/month discount on my contract because I contracted it online
  4. I got a 10%/month discount on my contract because I’m younger than 26

Which makes in the end an iPhone 4 at 149 euros instead of 249, and a contract at 43.11/month instead of 50.90.

I’m not sure that you could do it with a pay as you go (mobicarte) for the 100 euros discount, but you can still test. The 10% discount is not for every contract, so take care of it. Finally, the 3euros discount is for everybody at least :)

Only 2 USB ports on my MacbookPro

No Comments

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes)

I’m very happy with my brand new MacBook Pro 2010 15″ and we’re living a beautiful love story together :) But WHY THE HELL ARE THERE ONLY 2 USB PORTS? What do you want to do with that?.. Imagine you use a USB mouse of any other device like a 3G dongle, you already find yourself with only one port effectively available… And if never you dare to plug a USB stick that is too fat, it will be even impossible to use the second one.

Notice that it’s possible to have a third USB port on your macbook pro, but it will cost you to get the 17″ model instead (that costs not lest than 500 euros more than the entry 15″)

Yes if there is something I’d have to have against my Macbook Pro, it’s definitely the low number of available USB ports, it’s a pain sometimes…

Set property for States in Flex 4

No Comments

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes)

When you upgrade a project from Flex 3 to Flex 4 (and by the way, if you’re a student, you can have a free license for Flex Builder at http://www.adobe.com/devnet/flex/free/index.html), you probably encounter this error if you use States:

Error: State overrides may no longer be explicitly declared.
The legacy states syntax has been deprecated.

So if you used to have something like that:

<mx:State name="mainMenu">
    <mx:SetProperty target="{mainMenuContainer}" name="visible" value="true" />
</mx:State>
 
<mx:Container id="mainMenuContainer"></mx:Container>

It should be this way from now on:

<mx:State name="mainMenu"></mx:State>
 
<mx:Container id="mainMenuContainer"
    visible="false" visible.mainMenu="true">
</mx:Container>

Looking forward to the official livedoc for Flex 4 ^^

Save password for SSH login

No Comments

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes)

Nothing new with that, but as I never remember the correct procedure, I decided to write this reminder for myself :)

So, let’s assume you are user A on your machine A (in my case it’s my laptop), and you want to connect as user B to machine B (in my case it’s a dedicated server). And you don’t want to be asked userB’s password each time you log in. This tutorial was made for Linux OSs and openSSH.
User A on machine A wants to connect in SSH to User B on machine B

Read more…

Mobile plans in France versus United Kingdom

No Comments

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes)

My finale year of studies in Oxford comes to an end, and I’ll go back to France this summer… Having a look at the mobile offers in France, I nearly passed out. Here is a simple comparison between the cheapest mobile plan for iPhone (no publicity, that’s my phone!) in France and in the UK. This is for contracts without the phone (SIM only plan). The comparison is made with the same carrier in the both countries: Orange.

UK France
Plan: iPhone SIM only 25 Origami star pour iPhone
National calls: 600 minutes 60 minutes
Texts: Unlimited 10
Internet: Unlimited
(bandwidth reduced after 750Mo)
Unlimited
(bandwidth reduced after 500Mo)
Contract: No duration 24 months
Price: £25/month (= 30€) 36.90€/month (= £30)
Source: www.orange.co.uk

www.orange.fr

The situation in France: only 3 phone carriers, and a legal wall for any other company to enter the market.

The result: the 3 carriers agree on the prices, as there is no attempt to be competitive they can fix the prices they want, even if it’s 10 times more expensive than what it costs to them (60 minutes against 600 minutes, 10 texts against unlimited texts).

How dare they only give 10 texts a month? Come on, it costs nothing nowadays for the carrier to send a text… It’s far the time when France was the country of the human rights and freedom. Nothing’s made in France to help companies to work properly or to be competitive. And the UK is not even the cheapest country in the world for mobile plans, the prices in Austria for example will blow you away for sure…

Page 1 of 3123