July 2009 - Posts

Ok, some of you might find it bad that I'm triyng to relate Eclipse with Visual Studio too much, feature to feature. But I can't help it, having used Eclipse for the past 3 years.

 

So I was trying to find a functionality like "Open Resource" (CTRL + SHIFT + R) in Eclipse. I've been using Visual Studio for a good 4 months now and I found myself searching by using ctrl + shift + f (entire solution) and hope that something would match the keyword I type in. The latter is useful if you want to fnd a particular occurence of your search parameter, but I only wanted to find a file in our 10+ or more projects in one solution.

The solution was to append >of in the search box followed by a few words of the filename you're searching for.

>of <SPACE> <SOMETHING_THAT_THE_FILE_BEGINS_WITH>

A list of possible matches would appear below the search box.

 

Reference:

http://www.alteridem.net/2007/09/11/quickly-findopen-a-file-in-visual-studio/

Posted by lamia | 1 comment(s)
Filed under: ,

I was asked to solve a problem of parsing a float value in dutch format (9,6 instead of 9.6). The former would always parse as a whole number, 96 instead of 9.6). I read on the
documentation from sun, http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormatSymbols.html and I saw that a method called setDecimalSeparator(char decimalSeparator) was
available. Lucky for me!

I then opened netbeans and came up with the code below.

Normal 0 false false false MicrosoftInternetExplorer4 Normal 0 false false false MicrosoftInternetExplorer4

package decimalformattest;

 

import java.text.DecimalFormat;

import java.text.DecimalFormatSymbols;

import java.text.Format;

import java.text.ParseException;

import java.util.Locale;

import java.util.logging.Logger;

 

/**

 *

 * @author lamia

 */

public class Main {

 

    Logger logger = Logger.getLogger(Main.class.getName());

 

    public static void main(String[] args) {

        Locale locale = new Locale("nl-NL");

        DecimalFormatSymbols dfSymbols = new DecimalFormatSymbols(locale);

        dfSymbols.setDecimalSeparator(',');

        Format format = new DecimalFormat("#,###,###,##0.00#############", dfSymbols);

        try {

            Object parseObject = format.parseObject("9,5");

            System.out.println(parseObject);

        }

        catch (ParseException ex) {

            ex.printStackTrace();

        }

 

    }

 

}

Output:

run:
9.5
BUILD SUCCESSFUL (total time: 0 seconds)

try removing dfSymbols.setDecimalSeparator(',') and you'll see that it parses differently.

Output without dfSymbols.setDecimalSeparator(',')

run:
95
BUILD SUCCESSFUL (total time: 0 seconds)

Now, I had to translate this to something that Spring would understand. Say, I have a Spring app called my-app. In myapp-servlet.xml we had an old reference to java.text.DecimalFormatSymbols which also had a reference to a Locale object

Normal 0 false false false MicrosoftInternetExplorer4

    <bean id="locale" class="java.util.Locale">

        <constructor-arg index="0">

            <value>"nl-NL"</value>

        </constructor-arg>

        <constructor-arg index="1">

            <value>"NL"</value>

        </constructor-arg>

    </bean>

 

    <bean id="dfSymbols" class="java.text.DecimalFormatSymbols">

        <constructor-arg>

            <ref bean="locale"/>

        </constructor-arg>      

    </bean>


   
So I just added a new property

Normal 0 false false false MicrosoftInternetExplorer4

 

        <property name="decimalSeparator">

          <value>,</value>

        </property>    


       
Which makes dfSymbols bean look like this:

Normal 0 false false false MicrosoftInternetExplorer4

 

 

    <bean id="dfSymbols" class="java.text.DecimalFormatSymbols">

        <constructor-arg>

            <ref bean="locale"/>

        </constructor-arg>      

      

        <property name="decimalSeparator">

          <value>,</value>

        </property>           

    </bean>

 

Hope that helps!Wink

Posted by lamia | with no comments
Filed under:

Hmm... I feel like I just had a de javu... But anyway.. I hate browsing through a long log file. Does the GREP command in Linux exist on Windows? No... But windows have something like this...

find "The String You're Looking For" SomeFile.txt

So say, I want to find all occurrences of the word "error" when I execute ant from my commandline, I would do something like this:


c:\>ant someTarget > someLog

c:\>find "error" someLog

You get the idea. :)

Posted by lamia | 1 comment(s)
Filed under:

I'm pretty new to Test Driven Development and it's the first time I worked on an environment that adheres to its practices. Something I learned today is Write the Test first before you make any changes. This ensures that you know what you're writing your code against, and you make your solution fit the expected behavior, instead of the behavior trying to fit your solution.

I develop and maintain code. I didn't quite know that TDD can be used in the maintenance stage. I thought at first that it was only useful for new, ground up projects but I was wrong. It could also be, or maybe even more useful in maintenance projects. So again, why do you need to write the test first? Because your test must be able to fail if your designed solution is taken out, and pass if you put it back in.

Posted by lamia | 2 comment(s)
Filed under:

In my work I work with different code branches and requires me to switch from one directory to the other. Wouldn't it be good if we could give a directory a drive letter of its own? The following batch code does just that.

 

#define the directory you want to assign a drive letter to
SET CURRENT_WORKDIR=C:\sourcecodes\theultimateapp1.0
#SET CURRENT_WORKDIR=C:\sourcecodes\theultimateapp2.0
#SET CURRENT_WORKDIR=C:\sourcecodes\theultimateapp3.0
#delete current assignment to the drive letter if there are any
SUBST z: /D
#assign the directory a drive letter
SUBST z: %CURRENT_WORKDIR%

 

I usually use just 1 drive letter, just commenting code if I want to switch from one to the other as needed. Type this in a text file, save this as a .bat file and run the batch file.

 

Now, you might want this behavior to persist every time you start your computer. Here's a very good resource to do just that.

http://www.freeweb.hu/wsh2/ch13e.html

 

 

Posted by lamia | with no comments
Filed under: