Pages

Friday, December 14, 2012

How to generate hashed passwords with JBoss

If you want your JBoss to hash passwords for you can do it using the command line

In linux
java -cp client/jboss-logging-spi.jar:lib/jbosssx.jar org.jboss.resource.security.SecureIdentityLoginModule djordje

In windows
java -cp "c:/opt/jboss/lib/jbosssx.jar;c:/opt/jboss/client/jboss-logging-spi.jar" org.jboss.resource.security.SecureIdentityLoginModule djordje

Here a print screen of how to use the cygwin terminal in windows to hash the password:





Sunday, November 18, 2012

Fancy a cup of tea?

In most parts of Eastern Europe, they often drink it with lemon and honey,
in India with milk and cardamom,
in Spain they drink it just with sugar,
in Ireland they drink it with milk and some people with a fascinating new taste called brown sauce (If you dont belive me see this movie: Intermission).

But in all cases the recipe has 2 mandatory components:
  1. Boiling water
  2. Tea

In this video I am going to talk about a new design pattern that was created by Marco Castigliego, called
"The Step Builder".

"The Step Builder" is a variant of the creational pattern "Builder".
The advantages of using Castigliego's pattern are:

  • The user will see only one or few selected methods per time during the Object creation.
  • Based on the user choice different paths can be taken during the Object creation.
  • The final build step will be available only at the end, after all mandatory steps are completed returning an Object in a consistent state.
  • The user experience will be greatly improved by the fact that he will only see the next step

 methods available.

More information about this pattern and also a wiki definition of it can be found at Marco Castigliego's blog: Remove duplications and fix bad names

 Note: Don't forget to select the maximum quality in the video player




Monday, November 12, 2012

The all mighty regex

We often use regular expressions when programming.
In many occasions they make our live easier and help us avoiding lots of lines of code. I was just navigating around, and by a chance I found a blog that shows probably the one of coolest regex.
Have a look at this regular expression:


                                                                    
Personally I never used this one before. The thing that I find cool about it is, its simplicity.
For those who are not familiar with regex terminology, this one matches a character that is within(inclusive )the characters SPACE and tilde in the ASCII table.



Hehe.. cool, isn't it? I am looking forward to use it somewhere.

I can't resist, let's just give it a quick try :)

1:  import java.util.regex.Matcher;  
2:  import java.util.regex.Pattern;  
3:  public class AllMightyRegex {  
4:       public static void main(String[] args) {  
5:            String someASCIICharacters = "!#$%&\'()*+,-.0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";  
6:            Pattern pattern = Pattern.compile("[ -~]");  
7:            Matcher matcher;   
8:            for (int variableIndex = 0; variableIndex < someASCIICharacters.length(); variableIndex++) {  
9:                 matcher = pattern.matcher(getCharAt(someASCIICharacters, variableIndex));  
10:                 if(matcher.matches()) {  
11:                      System.out.println("The character: " + getCharAt(someASCIICharacters, variableIndex) + " matches the pattern");  
12:                 }  
13:            }  
14:       }  
15:       private static String getCharAt(String someASCIICharacters,  
16:                 int variableIndex) {  
17:            return someASCIICharacters.charAt(variableIndex) + "";  
18:       }  
19:  }  


Tuesday, November 6, 2012

How to print into a remote application server log with eclipse.




  1. From the debug perspective access the debug configurations
  2. Use the Remote Java Application option in the debug menu to create a new debug configuration.
  3. Enter the ip of the remote host and the debug port.
  4. Click on Debug
  5. Once the debugger is hooked, open the display view
  6. Type the command you want to execute and execute it.
  7. tail -f of vi into server.log file to see the results

Thursday, November 1, 2012

How to conquer the world? Well... you need a strategy

This weekend i went through old notes i had on  my hard disk, I wanted to refresh my mind about some design patterns.
Patterns is a topic I like very much and from my point of view they represent some foundation which is mandatory to understand if we want to have better understanding of software architectures.
The most popular authors that wrote about design patterns are known as GoF (Gang of Four), we could say that they are the icon every developer looks at when talking about design patterns. Their writings are present in almost every university and in many occasions are even a mandatory subject(Well.. at least it was in mine :) ).

I think the "Strategy" pattern was the first, or at least one of the first patterns i studied when I started with java. Also i noticed the large amount on articles on the web about this pattern.
Here a really good one you can read latter (But for now, focus on my one ;) ).

So since this pattern is so popular, and interesting, maybe it deserves a post.
Also since there are many articles on this topic already on the internet and all of them are very similar, I thought about making a little surprise at the end of my  presentation, to make it more fun and beautiful.
I hope you like it.




Note: Don't forget to set the quality to HD in the video player





Saturday, October 20, 2012

static factory methods, an alternative to public constructors

The most widely used technique to allow other parts of our programs, to get objects of a certain type, is to create public constructors.

1:  public class Product {  
2:        //..  
3:        public Product() {  
4:        }  
5:       //..  
6:  }  

There is also another technique that provides various advantages and it would be highly recommendable for every programmer to know.
Classes can provide static factory methods. This methods are another way of returning instances.

1:  public class Product {  
2:      //..  
3:        private int price;  
4:        private String description;  
5:          
6:          
7:        private Product(int price,String description) {  
8:              this.price = price;  
9:              this.description = description;  
10:        }  
11:        public static Product getNewProduct(int price,String description) {  
12:              return new Product(price,description);  
13:        }  
14:      //..  
15:  }  

This are some of the advantages of using this technique:

Methods have names, so we can be more descriptive when constructing our objects.
Constructors cannot have names, but methods can, so by having this types of methods we can express more fluently how the object is constructed.
So instead of this:

1:  new Product("ProductA",12);   

We can create our objects like this:
1:  Product.getNewProductWithValues("ProductA",12);  

We don't have to create new objects if we don't want to. 
Every time the keyword new is called, a new instance is created. In many occasions, specially in large systems, programmers need to be careful with resources. Some techniques to do that are:
-having cached objects and manage that they are cleaned properly.(Google for Singleton pattern).
-work with immutable objects which provide predefined state.(Google for Builder Pattern)
In the following piece of code you will see a very trivial implementation of a cached object:

1:  public class Product {  
2:        private static Product product = new Product();  
3:        private Product() {  
4:        }  
5:        public static Product getDefaultProduct() {              
6:              return product;  
7:        }  
8:  }  

This type of methods can have a subclass as a return type.
By using this type of methods, we can have big flexibility because we can use sub-classes as return types.
This is a very interesting feature which can allow us to create very powerful factories:

In the following example you can see how the static factory method can be used to create instances of subtypes or implementing types.
:
1:  public final class ProductFactory {  
2:        public static Product getProduct(boolean condition) {  
3:              if(condition) {  
4:                    return new HomeMadeProduct();  
5:              }  
6:              else {  
7:                    return new FactoryMadeProduct();  
8:              }  
9:        }  
10:  }  



  

Saturday, October 13, 2012

Installing maven in windows

Very brief video that just shows how simple it is to install the latest maven in a windows system.

Note: Don't forget to set the quality to HD in the video player





Share with your friends