Tuesday, December 7, 2010

Validate textbox in Graphical User Interface containing only numbers


Often it is necessary to validate the input data in the Graphical User Interface when received at the server side. According to the received parameters the server may be not called if the parameters are not in the desired format. This will lead to a saving in the used resources server side. This can be easily done by performing a basic validation on the properties of the object received. The validation proposed here below could be smaller by using regular expressions.
The programming code below just loop on a received string and determines if every character of the string is a digit isDigit(). The loop stops if a character is not a digit and returns false.




/**
*
* @author Jose Ferreiro
*/
public class Main {

/**
* This method checks if a String contains only numbers
*/
public boolean containsOnlyNumbers(String str) {

//It can't contain only numbers if it's null or empty...
if (str == null || str.length() == 0)
return false;

for (int i = 0; i < str.length(); i++) {

//If we find a non-digit character we return false.
if (!Character.isDigit(str.charAt(i)))
return false;
}

return true;
}


/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Main main = new Main();
System.out.println(main.containsOnlyNumbers("123456"));
System.out.println(main.containsOnlyNumbers("123abc456"));
}
}


OUTPUT of the main method:
True
False

HAPPY CODING

Saturday, December 4, 2010

Custom 404 Page Using JBOSS (for audit purposes)




Having a custom “page not found”, or 404 page, is an important modification for any website. It’s used to enhance the user experience by presenting an easy to understand message. Sometimes it is also useful to hide information contained in those pages as it reveals information about the server it self, release etc, etc


Setting up a user friendly error page is simple enough using Apache web server. Just modify the line in httpd.conf and point it to a static HTML document:

ErrorDocument 404 /the404_page.html

With JBOSS (or Tomcat-like Java container) application server, it’s slightly trickier. It has to be handled per web application basis. The change is done on the web.xml file, with these entries:

<error-page>

<error-code>404</ error-code>
<location>/404.html < / location >
< /error-page >

For the root directory, modify the web.xml in the ./deploy/jboss-web.deployer/ROOT.war/WEB-INF directory.

Thursday, October 28, 2010

Java lang String Calculate MD5

The java.lang.String class does not provide a faster way to code the MD5 algorithm, surely for security reasons.

Here a quick way to do implement is a a static class

1.import java.security.MessageDigest;
2.import java.security.NoSuchAlgorithmException;
3.
4.public class LMD5Gen {
5.
6. public static String md5(String input){
7. String res = "";
8. try {
9. MessageDigest algorithm = MessageDigest.getInstance("MD5");
10. algorithm.reset();
11. algorithm.update(input.getBytes());
12. byte[] md5 = algorithm.digest();
13. String tmp = "";
14. for (int i = 0; i < md5.length; i++) {
15. tmp = (Integer.toHexString(0xFF & md5[i]));
16. if (tmp.length() == 1) {
17. res += "0" + tmp;
18. } else {
19. res += tmp;
20. }
21. }
22. } catch (NoSuchAlgorithmException ex) {}
23. return res;
24. }
25.
26.}

Sunday, October 17, 2010

Middleware : Service-Oriented Architectures (SOA) using BPEL components

Future is the next generation of Business Integration through Service-Oriented Architecture (SOA). Legacy integration technologies are too complex and require proprietary skills to develop, support, and maintain. Standards have cleared the path to develop truly composite applications that leverage existing technology investments, promote mainstream developer adoption, and adapt to future technological advances.



Tuesday, September 28, 2010

Sistine Chapel on-line || Vatican City state

Check it out the online version of the Sistine Chapel (Italian: Cappella Sistina) at the Vatican City state (Italian: Stato della Città del Vaticano) by Michelangelo, the Italian Renaissance painter that paint it on the XV century.
Last week I had the privilege to be able to visit it.

http://www.vatican.va/various/cappelle/sistina_vr/index.html



Tuesday, August 24, 2010

The ultimate Wedding Query... (SQL Style)

I am running the following SQL query among the databases instances I managed in different MS SQL servers for fun....

At that point, I should say that the desired "tuple" has not yet been found :-( . . . .




Details of the SQL query follow:

--
-- Funny query
-- Date: 25 August 2010
--
-- The ultimate Wedding Query................ (SQL Style)

-- HUSBANDS QUERY

CREATE PROCEDURE MyMarriage(BrideGroom Male (25),Bride Female(20) )
AS BEGIN
SELECT Bride FROM Beautiful_ Brides
WHERE FatherInLaw = 'Millionaire'
AND Count(Car) > 20 AND HouseStatus ='ThreeStoreyed'
AND BrideEduStatus IN (B.TECH ,BE ,Degree ,MCA ,MiBA, PHD) AND Having Brothers= Null
AND Sisters =Null


SELECT Gold, Shares, Cash, Car, BankBalance
FROM FatherInLaw
UPDATE MyBankAccout
SETMyBal = MyBal + FatherInLawBal
UPDATE MyLocker
SET MyLockerContents = MyLockerContents + FatherInLawGold
INSERT INTOMyCarShed VALUES('Porsche')
END
GO

-- Then the wife writes the below query:
DROP HUSBAND;
Commit;

-- (-:

Tuesday, August 17, 2010

My Super Server - version 2010

The server that is presented is as worth as the car below (second hand)! Next, see some snapshots I took from the Operating System (Windows Server 2008 RC2 64 bits).





The monster: HP Proliant ML570R G4 server



RAM: 16 x 4 GB = 64 GIGABYTES !!!!! I may tell you with this you will not have problems with multi threading.




STORAGE of 12 x 1000 Gigabytes (1.0 TB) = 12 Terrabytes !!!! = > 12.0 TB
Additional storage of 1.0 TB for C and D drives. See snapshot below.



Happy surfing!

Thursday, July 29, 2010

Tuesday, July 27, 2010

Microsoft VBScript runtime error '800a01ad' ActiveX component can't create object

PROBLEM:

Server reports this error on a 64-bit Windows Server 2008 RC2 when running a COM object (dll ) under ASP page for a given web site when accessing the database.

DISPLAYED ERROR IS:

Microsoft VBScript runtime error '800a01ad' ActiveX component can't create object: 'XYXX.YYYY'

SOLUTION:

The issue is solved by going to the Application Pool tied to the web application, Advanced Properties... and setting "Enable 32-bit Applications" to True. I spent some minutes with this pain and finally had some relief :-)

Server is: IIS 7.5 under Windows Server 2008 RC 2 64 bit


Tuesday, July 13, 2010

2010 - La Roja - Campeona del Mundo - The red - Champions of the World

The day after still a bit sleepyyyyy. Un peu fatigué de la veille. Un poco cansadillo de la noche del fieston!!!

We did it!!! On l'a fait!!! Lo conseguimos!!!!







Monday, April 26, 2010

UN - Special - Wikipedia - Jimmy Wales

My comments based on the new technologies as Wikipedia was published on the UN Special magazine on the edition of April 2010 (see page 10). A very interesting interview of Jimmy Wales, the founder of Wikimedia foundation is also developped.

Link to the magazine (pdf file)

Sunday, April 25, 2010

Setting up a 3Com SuperStack 3 Switch 4924

The monster-> 3Com SuperStack 3 Switch 4924









For the initial switch setting up I used a workstation with terminal emulation software (Microsoft Hyperterminal) to connect to the console port of the Switch directly.



I connected directly to the console port using a standard null modem cable to the COM1 port on my workstation.



Adding the following properties to establish the connection... That is to say the default settings for the Switch.



Entering the credentials...



Sucessfull login :-)



Actually I also included this snapshot because the login prompt did not begin immediately, I pressed Return Carriage (RC) a few times before it started... Connection time is highlighted into red at the bottom on the left.



I selected the option gettingStarted


And that is all for this series! I just logged out :-).

Thursday, April 15, 2010

Quelques faits amusants

* Le muscle le plus fort du corps est la langue

* Un escargot peut dormir pendant 3 ans

* Les moustiques ont 47 dents

* Si Facebook était un pays, il serait le 4ème plus grand pays au monde entre les USA et l'Indonésie

* American Airlines a économisé 40'000 $ en 1987 en retirant une olive de chaque salade servie en première classe.

* La chaise électrique a été inventée par un dentiste

* A Tokyo, on estime qu'un vélo est plus rapide qu'une voiture pour la plupart des trajets de moins de 50 minutes.

Tuesday, March 16, 2010

Static Methods and Properties in Flex

Static Methods and Properties:

•Static methods, also called class methods, are methods that are declared with the static keyword.
•Static methods, which are attached to a class rather than to an instance of a class.
•Static methods, are useful for encapsulating functionality that affects something other than the state of an individual instance.
•Static methods can be accessed only through a class and not through an instance of the class.
•We cannot use the keywords this or super within the body of a static method.
•[reason : Both the this reference and the super reference have meaning only within the context of an instance method.]
•Static properties are not inherited by subclasses. This means that static properties cannot be accessed through an instance of a subclass. A static property can be accessed only through the class object on which it is defined.
•Although static properties are not inherited, they are within the scope chain of the class that defines them and any subclass of that class.

Monday, March 15, 2010

Resolve Flex’s error: “Type was not found or was not a compile-time constant”

I just faced the terrible nightmare of “Type was not found or was not a compile-time constant” error (Flex Builder) and I lost several time to figure out what the problem was. I realized that I was using the same name for MXML Application file which was already used by a class inside one of my packages. So, by renaming the file I solved the problem, but I was not completely satisfied and I looked for a way to avoid the error mantaining the same file/class name. Initially I tried to use namespaces, but as the reference says: “Applying a namespace means placing a definition into a namespace. Definitions that can be placed into namespaces include functions, variables, and constants (you cannot place a class into a custom namespace)”. I finally solved by renaming class references inside my package with the full qualified name (from MyClass to com.mysite.foo.MyClass). I also clean up the project under menu Project -> Clean...

Friday, March 12, 2010

Logging in Log4j

Locate the log4j.cfg file ...


log4j.rootLogger=INFO, stdout, F
... etc ...
log4j.logger.org.apache.commons=info
log4j.logger.org.apache.axis2=info
log4j.logger.org.apache.axiom=info
#log4j.logger.org.apache.commons.httpclient=debug
#log4j.logger.httpclient.wire=debug
#log4j.logger.httpclient.wire.header=debug


So when you want to see the logging you can remove the "#" as required.

Some relevant links are here ...
"http://hc.apache.org/httpclient-3.x/logging.html"
"http://logging.apache.org/log4j/1.2/manual.html"

Ressources Monitor (Windows 7)

Tuesday, March 2, 2010

Automatize your task with ANT (copy folders and subfolder on a click)

Using the same build tool for all your projects simplifies your life and keeps things easier to manage. Many developers (especially Java developers) are already using Ant.

See the example below to copy a bunch of files on the fly.

< target name="_copy-file-local-server" >
< echo message="Copying compiled files -> server folder"/ >
< copy todir="destinationFolder" overwrite="true" >
< fileset dir="sourceFolder" >
< include name="**"/ >
< /fileset >
< /copy >
< /target >

See http://ant.apache.org/ for details

Friday, February 19, 2010

ActionScript 3 - Call to a possible undefined method setTimeout

You need to import the utils package in your class.

import flash.utils.*;

Thursday, February 4, 2010

La magie du PageRank de "gloogloo"


T'as combien en PageRank? Telle est la question! Au milieu de 500 autres paramètres (dixit Google), le PageRank est l'algorithme d'analyse des liens concourant au système de classement des pages web utilisé par le moteur de recherche Google pour déterminer l'ordre dans les résultats de recherche qu'il fournit.

Ce nom - marque déposée - vient de l'un des fondateurs de Google, Larry Page. De manière assez cocasse, le gouvernement américain dispose de certains droits sur cette invention ayant participé au financement de la chose. En termes de fonctionnement, tout à été écrit sur le sujet et le fonctionnement du PageRank, mais cela reste un secret aussi bien gardé que la recette du Coca-Cola. A épisodes plus ou moins réguliers, des étudiants et chercheurs en informatique du monde entier se transforment en Champolion de l'algorithme et affirment avoir trouvé la Pierre de Rosette "googlienne". Selon l'encyclopédie Wikipedia , la propriété intellectuelle accordée à Google pour l'utilisation exclusive du PageRank prendrait fin en 2011. Il existe des centaines des milliers de pages sur le sujet, le PageRank ayant même fait l'objet d'un concours de mathématiques en 2008. Selon des nombreux observateurs, le PageRank le serait aujourd'hui moins dans le rang d'affichage de ses pages, sa prépondérance diminuant par l'adjonction des nouveaux algorithmes (tout aussi secrets) dans les méthodes d'évaluation du moteur de recherche et des services associés.