Google search bar

December 12, 2007

Prototype extends arrays so they should not be used as hash sets

We've started using the Prototype js library. We were having some weird behavior with some arrays in existing code when the Prototype lib was included in a page.

Turns out that Prototype adds some methods to Array. They are good, but one should be careful using Array objects as hash(key-value) sets.

Here is the blog entry we found that cleared everything up.

The skinny, Use Object as a hash, nothing else.

Thanks for the insight, Andrew Dupont.

July 10, 2007

Java reflection: primitive arguments in methods

Suppose that we want to reflexively invoke an instance method for a java object. Further, suppose that one or more of the method arguments is of a primitive type (i.e. int, small, double, ...).

In the Class.getDeclaredMethod(String, Class[]) method, you pass in a string representing the method name and an array of Class objects representing the types of any arguments.

For the following class :

public class Reflector {
public void intMethod(String aString, int anInt) { /* Some Code */}
public void integerMethod(String aString, Integer anInteger) { /* Some Code */}
}

You would get the methods reflectively like so:

. . .
Reflector r = new Reflector();

Method m = r.getClass().getDeclaredMethod("intMethod", Class[] {String.class, Integer.TYPE});
Method m2 = r.getClass().getDeclaredMethod("integerMethod", Class[] {String.class, Integer.class});
. . .


And invoke them thusly:

. . .
m.invoke(r, Object[] {"MyString", Integer.valueOf(100)});
m2.invoke(r, Object[]{"MyString", Integer.valueOf(100)});
. . .


For m.invoke, you wrap the int in the wrapper class since we're passing in an array of Object. Java automatically tries to unwrap it for you.

For an argument that is of primitive types use the following when defining the signature:
byte => Byte.TYPE
short => Short.TYPE
int => Integer.TYPE
long => Long.TYPE
float => Float.TYPE
double => Double.TYPE
boolean => Boolean.TYPE

June 27, 2007

Velocity


Velocity Template Language (VTL)

Statements begin with '#'
ex. #set( $a = "Velocity" )

References (varables, properties, and methods) begin with '$'
Formal notation ${}
Quiet notation $! or $!{}

Literal string delimited by single-quote
ex. 'I know strings'
Interpolated string delimited by double-quote
ex. "I love $a" => I love Velocity

## This is a single line comment

#* This is
a
multiline
comment *#

#**
This is a documentation comment
@author Me
@version 5
*#

escaping characters
$$ => $
This snipet
#set($foo='dude')
Hi $foo
Hi \$foo
Hi \\$foo
Hi \\\$foo
produces
Hi dude
Hi $foo
Hi \dude
Hi \$foo

If a reference is undefined,
Hi $foo
would produce
Hi $foo
because $foo is undefined
while
Hi $!foo
produces
"Hi "
without the ".

June 19, 2007

Internet Explorer on Linux

http://www.tatanka.com.br

This site offers an option for easily installing several versions of IE for LINUX.

April 16, 2007

Use Windows CE devices with Linux (Kubuntu)

There's a good example at: http://doc.gwos.org/index.php/Pocket_PC_Evolution

The above is for setting up a syncing relationship.  I'm just going to set it up to browse the file system.

  1. Install these packages:
    1. synce-kde
    2. synce-multisync-plugin
    3. synce-dccm
    4. synce-serial
  2. Setup synce
    1. Connect the Pocket PC via USB
    2. run: 'dmesg'
    3. Look for a line like 'usb 4-2: PocketPC PDA converter now attached to ttyUSB0' and remember the ttyUSB0 part.  That's the device file for the PocketPC.
    4. Run: 'sudo synce-serial-config ttyUSB0', replacing ttyUSB0 with the appropriate device, if necessary.
    5. Run:'dccm' to start the daemon that will keep the connection alive.
    6. Run:'sudo synce-serial-start' to start the connection
    7. The above mentioned tutorial suggests running 'synce-pstatus' to get info on the device
    8. In konquerer, go to the address 'rapip:/'
    9. You're looking, hopefully, at your device's filesystem!

I haven't set up a partnership yet.  That's next.


April 11, 2007

Using RSYNC (or any other system command) from RUBY

I found a blog entry concerning using rsync from ruby for doing backup. To use RSYNC from within Ruby, do something like this

> system "rsync -<option(s)> <from> <to>"

You can invoke any system command in this way.

April 05, 2007

Followup: Linux CVS clients

Last month I moaned about how disappointed I am that there is no cvs client for linux that makes me as happy as TortoiseCVS for windows. Well, I like lincvs enough to say that it's pretty good. It shows me what files have been altered at a glance. It allows templates and caching for commit messages.

April 02, 2007

CVS: find different or unmanaged files

Suppose you want to find the files in a local directory that are not under CVS version control.
  1. cd into the directory
  2. run "cvs diff -l --brief"
You will see a list of differences. Files not under version control will be shown with a '?'

March 27, 2007

CVS update misses new directories

Suppose you've checked out a local copy of a source tree from the repository. You work in it. Other's make changes and add new directories to the project.

You run cvs update and you only get the directories that you checked out originally. So, instead, execute cvs update -d. This will include directories not in your working copy.

Linux CVS clients

I have been disappointed by Linux's GUI CVS clients. I've tried a bunch and none is quite as good as TortoiseCVS, in my never-to-be-humble opinion. They seem to be just GUI shells for the CVS command-line client.

March 24, 2007

Help! I can't update my linux install

I use linux (Ubuntu) and KDE. When I open adept, the package manager, I get a message saying the package database is locked and I can't make any changes. The problem wasn't resolved when I restarted. I did a google search for the words "ubuntu", "adept", and "lock". I found this thread on the problem that contains a command to restart the stuck install that was causing the problem.

The command is:
dpkg --configure -a
You might need to prepend sudo

March 23, 2007

linux environment variables

You set an environment variable so it persists across sessions in "/etc/environment". You put a line that looks like this:
variable_name=value

For example
CVSROOT=:ext:boso@dumbcvs.dumbdomain.com:/cvsroot

or
JAVA_HOME=/usr/local/jdk6.0.0

ssh without a password

I found an article that explains how to set up SSH so you can log in on a remote machine without typing your password. For example, you can access a remote CVS repository without having to type you password over and over.

Thanks to mbonati at CalTech!

I quote the steps, just in case the page disappears:

What must be done, then , is to generate a public/private key pair, and copy the public part into the appropiate place on the server side.
For doing this, on the user's home directory, on the client machine, type

local> ssh-keygen -t dsa -f .ssh/id_dsa

-t tells the type of encription
-f tells where to store the public/private key pairs. In this case, the .ssh directory on home is being used

A password will be asked; leave this part blank, just pressing
Now, go the .ssh directory, and you will find two new files: id_dsa and id_dsa.pub. The last one is the public part. Now, copy the public key to the server machine

local> cd .ssh
local> scp id_dsa.pub user@remote:~/.ssh/id_dsa.pub

Of course, this time you will need to enter the password.
Now, login into the server machine and go to the .ssh directory on the server side

local> ssh user@remote
remote> cd .ssh

Now, add the client's public key to the know public keys on the server

remote> cat id_dsa.pub >> authorized_keys2
remote> chmod 640 authorized_keys2
remote> rm id_dsa.pub

remote> exit

and that's all.
Next time you log into the remote server, no password will be asked.
Note that this sytem will work while none of the machines change its IP address and for the specific user, so it is still safe.

March 15, 2007

Running Tomcat from Eclipse (using the server view from WST)

From the eclipse server view (since WST is installed) you can create a new server.

  1. right-click in the view and selecting new > server
    1. Select the server you will be using (it was tomcat 5.5 in my case). You will want to have the server installed already.
    2. Choose a host name
    3. Choose a runtime. If there isn't one available, create one (press the available button)
  2. Press next
    1. Select any web projects you want to run on the new server. If there aren't any, you'll be creating one soon, I wager.
  3. Press finish and you are done.
Set up a new project, create a new "dynamic web project". That has some really nice stuff in it for managing the project. The jars in lib directory can automatically be part of the classpath. You can associate the project with a server that you've defined (or that you define after creating the project, if you wish).

Don't let eclipse overwrite the tomcat config (unless you want to)

From inside the server's editor (right-click the server in the view and select open) select the option to "Run modules directly from the workspace". Now any configuration that you have in the server's conf/ directory is safe from changes you make to the config of the server defined in eclipse.

In the same editor you can set up ports, MIME mappings and other important stuff.

Note: If you're going to have the server listen on port 80 rather than 8080, linux' root user is the only one that can bind that port. So, in linux you'll need to run eclipse as root. Or maybe you can come up with a better solution. Let me know if you do. This article describes other ways of running tomcat on port 80 with a user other than root. I have not tried these solutions, let me know how the work for you.

Making the jump to linux

With some help from another engineer at work, I've wiped my computer clean of windows xp and installed Ubuntu. I then added KDE and off I went (I know the I could have started with Kubuntu, but...).

I downloaded the linux versions of Eclipse, Sun Java 6 SDK, and Oracle SQL Developer. I added the Web Tools Platform to eclipse for JSP, Tomcat, etc.

With those tools I was ready to go.

Here's where I had some problems. I tried to start sqldeveloper and it just threw exceptions. The problem? I had not set the JAVA_HOME environment. So I ran this command:
   > export JAVA_HOME=/path/to/jdk

Now sqldeveloper starts just fine.

But I don't want to have to do that every time. So I put the command above in the /usr/environment file. Now every time I start a session, the environment variable is set.

February 24, 2007

Don't break the build. Test it!

The most basic rule of developing software as a team is, "Don't break the build."

If you commit code or other project files that make the build break, you've messed up everybody's work.

Today, I committed some code when I was asked and It broke the build. Once someone had updated, they could no longer build the web app we're working on.

So, never commit without testing that the build works!

February 22, 2007

Struts styleId (What a way to name a form)

I'm new to Struts. I'm in my second week of using/learning Struts 1.2. Any framework, technology, pattern, or what-have-you has its weirdnesses.

Here's the first really weird thing that I've found in Struts: To give an identifier to an <html:form> tag you set the styleId attribute.

Here's some background: In an HTML page you can place a <form> tag. This allows you to get information from the user. The Struts method of placing a form in a page is the <html:form> tag shown above. In HTML, if you want to give the form an Id you would do something like this:

<form id="someId"> form stuff </form>

In Struts you would write:

<html:form styleId="someId"> form stuff </html:form>

So much for reasonable names.

February 16, 2007

Purpose

I have this idea that it would be helpful to list some of the problems that I run into in my young career as a Software Engineer. In the future I will post articles on mistakes, difficulties, and solutions that I encounter in doing my job.

Come back soon.