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 :)
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? :)
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:
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:
And that’s! it you will include and get an instance of the “Class”
A lot of people ask me how do you make the classic invite page that almost all the Facebook applications have, something like this:
If you are using FBML in your application this is quite simple you only need a FBML tag like this one:
I make a little explanation of each attribute:
action: here you have to add the page that the user should be redirected after the invite process.
method: POST or GET (simple HTTP methods)
type: generally here you put the name of your application
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
actiontext: here you put the title of the page
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?
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:
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!
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:
So basically here we have two functions:
Init(): where we add a listener in the keyUp event, so everytime that the user press a key the function “shortcutListener” will be called.
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?
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:
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!