Calculate verification digit to one Uruguayan id number

April 22nd, 2008

Recently I faced the problem to calculate the verification digit of the Uruguayan id numbers.The process is very simple, but requires some steps.In Uruguay the ids are composed by a number of 7 digits. So for calculate the verification digit (number between 0 and 9) we have to do this:Multiply each digit for this digits (according to the digit position): [2 9 8 7 6 3 4]So for example for the id number 4048458 we will have to do: 4*2, 0*9, 4*8, 8*7, 4*6, 5*3 and 8*4after that we will have to sum the results so we have:  (4*2) + (0*9) + (4*8) + (8*7) + (4*6) + (5*3) + (8*4) = 167now we take the number 167 (obtained in the previous step) and we obtain the mod 10, so: 167 MOD 10 = 7Now we take the 7 (obtained in the previous step) and we make: 10 - 7 = 3 and here we have the verification digit: 3That’s it :) 

Register global keyboard listeners in Flex

April 12th, 2008

Hi All!In many applications you will need to register a global keyboard listener to your entire application, this is easy to make in Flex but.. is not so straightforward or transparent.To do this the best way I found until now is this one: Application.application.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);  With that line of code you will set the event listener to the stage of your application and everytime a key is pressed it will call to your function named “keyPressed”. Now is easy right? :) 

Load classes dynamically in PHP

February 1st, 2008

Hi all! I am returning to my blog activity after a couple of weeks of absence :)

Here I want to show something that I has to deal recently.

Maybe you will never have to deal with the kind of situation that I will explain here, but in general when you make tools or some kind of framework you will have to do it.

The situation that I am going to explain is how to load and instantiate a class in runtime in PHP. Basically from a source file that we know that has some kind of class we will load a particular class.

Lets paste the sample code and I will describe each line, here is the code:

php_runtime_1.png

Basically you need 3 things:

  • First file_exists to be sure that the file that contains the class code exists
  • require_once: this will include the file that contains the class code
  • class_exists: This will check if the class exists or not

After that, if we pass the 3 functions described before you are sure that you have access to the class so you can make a normal “new”.And finally you will need the file Class.php:

php_runtime_2.png

And that’s! it you will include and get an instance of the “Class” :)

Invite page in Facebook applications

January 9th, 2008

A lot of people ask me how do you make the classic invite page that almost all the Facebook applications have, something like this:

invite_2.png

If you are using FBML in your application this is quite simple you only need a FBML tag like this one:

invite_1.png

I make a little explanation of each attribute:

  1. action: here you have to add the page that the user should be redirected after the invite process.
  2. method: POST or GET (simple HTTP methods)
  3. type: generally here you put the name of your application
  4. content: here you have to write the content that you want in the invitation, generally you add some text with a link to the application install page
  5. actiontext: here you put the title of the page
  6. exclude_ids: this is a very important attribute, here you have to pass the Facebook ids of the persons that you don’t want to appear in the invite screen. One good example is exclude the persons that already have the application installed, this has sense right? I mean why invite a person who already have the app installed? :)

So this is it, enjoy it! :)

Make an image button in Flex

January 8th, 2008

In some point maybe you need to add a button like an image in your Flex applications. With this I mean an image that can be clicked and that show a hand cursor when we are over the button.

Make this is very simple but you have to play with two properties of the image component, this properties are:

  • useHandCursor
  • buttomMode

It is vital that set true to both properties because if we set true only to “useHandCursor” the hand will not be showed. So all this used in addition with the thing that I showed in my last post (about how to open a new link) we will get a nice image button. As we can see here:

Open a link using Flex

January 6th, 2008

Hi all!

Recently I had to open a URL in a new window from my Flex applications… after a little search I found a straight and easy solution, here is it:

var url:URLRequest = new URLRequest(”http://www.infuy.com/blogs/alex/”);

navigateToURL(url,”_blank”);

And that’s it! I love when you can make something with only a few lines of code :)

Count the number of invites in a Facebook application

January 4th, 2008

When we are developing Facebook applications, in some point we will have to count the number of invites that a user make.

Actually there is no way (or at least I don’t know how) get the number of invites that the user made in his history inside our application (maybe can be done with FQL but I am not sure how).

What we can do is make that tracking in our code, how? tracking every single invite that the user make.

if we use the <fb:request-form> tag is very straightforward. As you may know in this tag you set an “action” attribute where do you specify the page that should be redirected after the invite is made and Facebook pass in the request a parameter called “ids” to that action. That parameter is an array containing all the ids that the user invited. So easy right?

So if we want to track how many invites made an user we only have to track this info so later we can make a sum of this counts and that’s it! :)

The sad reality…

December 31st, 2007

I found this image… it is sad… but you have to be honest… .it’s very true!

depressing.jpg

Add global key shortcuts in Flex applications

December 30th, 2007

In some point you will have a customer that will ask you to put some shortcut to your application, for example the classic “if I press Ctrl+S I want to save something”.. so you will have to add key shortcuts to your app, I made a simple example of how to do it, here is the code:

flex_shortcut.png

So basically here we have two functions:

  1. Init(): where we add a listener in the keyUp event, so everytime that the user press a key the function “shortcutListener” will be called.
  2. shortcutListener(): here we add the logic for our shortcut(s), basically here we are saying: “if the control and shift key are pressed together with the key who his code is 19 we show the alert” and the key with code 19 is the “S” key. So in conclusion if the user press “Ctrl+Shift+S” we will show the Alert in the rest of the cases we will not show anything. Easy right?

Make an AJAX call with the Extjs framework

December 28th, 2007

Every day it’s more common make AJAX calls in our Web applications, so here is a very easy way to make it using the Extjs framework.

Here is the code sniped:

ajax_call.png

As we can see this is a very easy task to do with Extjs, we only have to set the url of the service that we want to call, the method that should be used and the functions to handle the success or the failure.. and that’s it! :)