Run Firefox 2 and Firefox 3

Gah, why would you want to run both? Well, Firebug is the suck in Firefox 3. I’ve been doing a lot of javascript/ajax development lately.

When using Firefox 3 and the Firebug console, I get the following error occasionally:

commandLine.evaluate FAILS: [Exception... "Security Manager vetoed action" nsresult: "0x80570027 (NS_ERROR_XPC_SECURITY_MANAGER_VETO)" location: "JS frame :: chrome://firebug/content/commandLine.js ::  :: line 100" data: no]

Lifehacker had a nice post on how to run Firefox 2 and 3.

For most cases Firefox 3 is just fine. But for the serious javascript coder, Firebug just isn’t ready for prime time in Firefox 3.

Run Firefox 2 and Firefox 3

Ubuntu upgrade broke WordPress

Something with my past two Ubuntu upgrades broke all the internal links on my blog running on WordPress.

It turns out the upgrade process changed the name of the target link on the .htaccess symbolic link file under my WordPress install directory.

After the install this is what was linked:

.htaccess -> /etc/wordpress/htaccess

Notice the missing “.” in .htaccess.

To fix it, I had to update the link to with

 >> ln -sf /etc/wordpress/.htaccess .htaccess

All the links work again!

Ubuntu upgrade broke WordPress

Randy Pausch – The “Last Lecture”

Back in college, I volunteered to help on “Women in Computing Day” to teach middle schoolers programming using Alice. I also helped teach an undergraduate teaching assistant position for Engineering Fundamentals, the class all engineering students were required to take. The course used Alice to introduce the students to programming concepts (loops, methods, conditional logic, etc).

I thought Alice was a really innovative way of teaching programming. It was GUI-driven programming that was expressive enough to do cool engineering stimulations, but with the simplicity that middle schoolers could understand and use it.

The other day, my mom asked me to find the “Last Lecture” by Randy Pausch, some professor that made this speech. She had heard about on the T.V. and was interested in seeing what it was all about. I found the YouTube video and began watching it. To my surprise, Dr. Pausch’s work has crossed my path. He is the creator of Alice.

His speech is very inspiring. Watch it.


Randy Pausch – The “Last Lecture”

Ruby: ! versus not operator

I was writing some code in an erb template that looked like this:

<% if @user && not @user.errors.empty? -%>
#do stuff
<% end -%>

This resulted in a syntax error. Huh? What’s wrong with this?

Turns out it’s an outstanding Core Ruby bug.

As shown in the ticket if we have a method foo

def foo(parameter)
  puts parameter.to_s
end

using the ! and the not operator on various method calls show us that the ! and not operator are not interchangeable in practice.

foo(!(1 < 2)) # works fine
foo(not(1 < 2)) # generates syntax error
foo(not 1 < 2) # generates syntax error
foo((not 1 < 2)) # works fine

Changing the my code to the following fixed my issue:

<% if @user && !@user.errors.empty? -%>
#do stuff
<% end -%>
Ruby: ! versus not operator

Java WTF: Reflection API and Annotations

I got some exposure to custom Java 5 Annotations today and came across a noobie mistake.

Here’s my annotation:

public @interface Annotated {
}

Pretty simple, right?

Here’s a test class that uses the annotation:

import java.lang.annotation.Annotation;

@Annotated
public class Main {
    public static void main(String[] args) throws Exception {
        for(Annotation ann: Main.class.getAnnotations()) {
            System.out.println(ann);
        }
    }
}

What does this print?

Nothing!

Well, WTF?

Turns out Annotations are not run-time accessible unless you declaratively specific it via @Retention. The updated annotation looks like this:

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface Annotated {

}

By default, the Retention is specified with RetentionPolicy.CLASS which, per the javadocs, “Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time.”

RetentionPolicy.RUNTIME allows the annotation “to be recorded in the class file by the compiler and retained by the VM at run time, so they may be read reflectively.”

File this one under, RTFM.

Java WTF: Reflection API and Annotations

Java WTF: Calendar vs Date

I’ve been doing some date math at work and I came across something I thought was wack.

Check this out:

Calendar cal1 = Calendar.getInstance();
Thread.sleep(500);
Calendar cal2 = Calendar.getInstance();
Thread.sleep(500);
Date now = new Date();

System.out.println(cal1.before(cal2));
System.out.println(cal1.before(now));

What do you think this snippet prints (It compiles, I promise!)?

Looking at the code, it shows that we are getting three snapshots in time, waiting half a second between snapshots, and assigning those values to cal1,cal2, and now, respectively. I put in the Thread.sleep() to illustrate the point more clearly. The first print statement compares the first and second snapshots in time, returning true if the first is before the second. The second print statement returns true if the first is before the third snapshot.

Logically, we would expect both print statements to prints true. However, this outputs:

true
false

But, how could the first snapshot be before the second snapshot but not the third?

Putting up the javadocs, gives us our answer. The Calendar before and after methods always returns false if you don’t pass it a Calendar object. Why? I have no idea. Why not just have the method signature take a Calendar object? I mean, I guess this allows you to extend Calendar to be able to call after/before on whatever kind of classes you want to support…but does it really make sense to compare a Calendar to a Monkey class? This is what I call a Java WTF.

Java WTF: Calendar vs Date

Javascript Password Revealer using Prototype

Inspired by the latest Coding Horror post, here’s an code snippet that allows you to implement a password revealer using the Prototype JavaScript library.

Check it out in action below.



I wouldn’t mind seeing more web forms adding this feature for password fields.

Javascript Password Revealer using Prototype

Using JMeter for load testing

I came across JMeter a while back but never got a chance to try it out. From the JMeter website:

Apache JMeter is a 100% pure Java desktop application designed to load test functional behavior and measure performance. It was originally designed for testing Web Applications but has since expanded to other test functions.

This weekend I was able to test load on my 256 slice which this blog is running on. Here’s what I did:

  1. Download the binary
    You can get the binary here.
  2. Unzip the tarball/zip file
    I extracted it file to /Users/theo/tools/jakarta-jmeter-2.3.1
  3. Start up JMeter
    Go to the bin directory. Run jmeter.sh (jmeter.bat if using Windows) from the command line.
  4. Create a Test Plan
    Just give a name and any description you want for your test plan.jmeter_create_test_plan
  5. Create a Thread Group
    A thread group allows you to specify the amount of load you want to simulate. Select your test plan from the left Tree view, right-click, and select Add -> Thread Group.

    Configurable fields include:

    • Number of threads – the number of connections or users you want to simulate
    • Ramp up period – the amount of time in seconds to take to reach the number of threads specified. If you choose 0, all of the threads will be created at the start of the test.
    • Loop count – you can specify to loop indefinitely or provide a number of times to run through the test.

    jmeter_create_thread_group

  6. Add a Sampler
    A sampler is a type of request you want to make. In this example, I used an HTTP request to test load to a web server. It’s good to note JMeter supports multiple types of samplers including web services, JMS, and JDBC. Add a sampler by selecting the Thread Group you just created, right-click, select Add -> Sampler -> HTTP Request.

    Configurable properties include:

    • Server Name – what the ip or url is to the server the request it to
    • Port – the port the server is listening to
    • Protocol – the protocol (http, https, etc)
    • Method – HTTP method (POST,GET, PUT, DELETE, etc)
    • Path – the URL path to request

    jmeter_create_http_request

  7. Add a Listener
    A listener allows you to collect data points and display them in some fashion like a graph or a table. I used the Graph Results listener by selecting the Thread Group, right-click, select Add -> Listener -> Graph Results.
  8. Run the test!
    Now we are ready to run the test. From the file menu bar, select Run ->Start. You will be prompted to save your test plan. You can save it or just hit “No”. You should see data points begin to be plotted on the Graph Result or whatever listener you selected.

    jmeter_graph_results
    I monitored the usage from my slice as well and this is what top showed me:

    slice_top_load_test

    You can see the 5 threads we specified in the Thread Group taking up 5 apache processes.

  9. Interpret the results
    Tests are worthless without interpreting the results. So, what the heck does this graph tell me? Pretty good documentation can be found here. Basically, given the load scenario we have setup, my slice can handle ~643 requests/minute or ~11 requests/second. I am not sure what kind of numbers I should be getting but these seem pretty good to me. One last thing to note is that JMeter is not a web browser so these metrics don’t include rendering time or execution of any JavaScript.

Overall, JMeter seems to be a great open source tool to test different kinds of load on servers. I look forward to trying it out at work. One last thing I came across is JMeter integration with your Ant build process. Check that out here. I would like to hear about other people’s experiences with JMeter, too.

Using JMeter for load testing

Prior work experience not needed?

Jeff Atwood just posted an article on the myth that the more years of experience a developer has, the better candidate they are for a position. In the article he references a previous post that spoke to the hypothesis that there is no correlation between skill in programming and experience. This is exactly what I was thinking when I wrote my reaction to disillusioned young IT workers.

I’m still early in my career and I’ve tried to stay on a career path that is driven by what I enjoy doing, which is hacking away at code. At the same time, I am not blind to the fact that companies do look for work experience in specific areas. This certainly helps you get your foot in the door. One thing I’ve struggled with is how do you make the transition into getting that sought-after experience?

While I have programmed in a number of different programming languages, these experiences are based on my own pet projects and curiosity of the languages. On the other hand, my professional experience can be summed up as a Java developer. I’ve been working with Java since I got out of school. While I think working with Java is great since I feel I can be productive in it and there are plenty of career opportunities, the IT industry evolves over time and we see other languages gain traction.

programming_languages_absolute

programming_languages_relative

I don’t have any hard statistics, but I suspect the number of core programming languages an average developer extensively works with throughout their career is probably around 10-12. If you count all the supplemental languages that come with working in certain languages, like HTML, JavaScript, or SQL, this number is probably closer to 20. That sounds like a reasonable guesstimate and if true, I’ve got a long way to go.

This got me thinking about how do I continue to learn if my day-to-day is limited to one programming language. Here’s some advice I have for other Java developers.

  • Follow open source – open source projects are a great way of getting exposure to a lot of the Java/JEE platform. The Java platform is a really big environment to be playing with. Open source has provided baselines for everything from database ORM projects like Hibernate/iBatis to MVC frameworks like Spring MVC/Struts to messaging infrastructure with ActiveMQ/Mule to web services with Xfire/Axis2. There is a lot to be learned and I never see a job description for Java developers without some mention of a Java open source project.
  • Change the focus – What I mean here is change what you are doing most of your work relative to the system. At my first job, I mainly worked on the front-end so it was all HTML/CSS/JSP and Controllers. After awhile, I was interested in doing more of the back-end and building out infrastructure with DAOs and web services. At my current employer, I started off again on the front-end. Luckily, it was with a different MVC framework so there was good exposure there. More recently, I’ve had the opportunity to work on infrastructure and I’ve been exposed to about five new technologies I never worked with before.

By doing this, I’ve gained a lot of experience in a short amount of time with respect to working in Java. Basically, it allowed me to get more in-depth experience with Java by using Java in different contexts. This is a great start and if I was planning on working with Java my entire life, I could always continue down this path but that’s not reasonable.

HR departments love to see previous experience and it reminds me of the catch-22 that recent college graduates face. They want a job but the employer wants prior experience. They can’t get experience if the employer doesn’t them a job.

I would love to hear from people who have worked with multiple programming languages and made the language transition between jobs. If a company had a .NET position or a Rails position and you never had experience in the language, what made the company hire you and allowed you to beat out other candidates that probably had more language experience than you? What inspired you to make the paradigm shift? What advice do you have for others developers with language-limited experience?

Prior work experience not needed?