My thoughts as an enterprise Java developer.
Monday, December 17, 2007
Telecommuting
Technorati Profile
Wednesday, December 12, 2007
Subversion: Moving tags
Use case: We have thousands of "maps" and we want to tag which version of each map is the "production" version. We need to be able to easily get the production version of all maps.
Can anyone suggest a better way to address our use case?
I have considered properties also but then we can't get the prod version of all files easily. Merging to the tag doesn't appear to be very easy either.
Monday, November 26, 2007
IntelliJ default class javadoc comment
User: jstauffer
" it could create a line with "@author jstauffer
". The other lines that it creates (Date and Time) probably don't have javadoc syntax to use but why not use the javadoc syntax when available?For reference here is an example:
/**
* Created by IntelliJ IDEA.
* User: jstauffer
* Date: Nov 13, 2007
* Time: 11:15:10 AM
* To change this template use File | Settings | File Templates.
*/
Naming abstract classes
Normally I see abstract classes named as Abstract
Class. But when there are many abstract classes that leads to needing to type at least Abstract
C when using code completion. Therefore I suggest that abstract classes be named ClassAbstract
so that code completion is more usable. "Abstract" is a modifier on the class name anyway and it doesn't need to be in the primary position. What do you think?
I know this isn't a huge deal -- I am just suggesting it as a minor improvement.
Wednesday, November 21, 2007
Defaults have consequences: Microsoft Word margins
Friday, October 19, 2007
Autoboxing quiz
param
method will be called from the autoboxing
method? If one param
method is commented out then it will have no problem calling the other.private static void autoboxing() {
Integer integer = new Integer(2);
param(integer);
}
private static void param(int param) {
System.out.println("param(int " + param + ")");
}
private static void param(Object param) {
System.out.println("param(Object " + param + ")");
}
Thursday, October 18, 2007
Website idea
Make a website where the user can keep a list of things that they need/want to buy.
Allow easy management of that list (through web, WAP, SMS, etc).
Then....
Work with stores so they the user can get a list of all of the items in the list that the given store has. The store could even allow printing the list from a kiosk in the store (registry computers) and would include the location, price, etc. The stores would benefit because people would probably buy more if they remembered what they wanted to buy and they would buy items that they didn't know the given store had. You could then charge the store a small fee so that you wouldn't need ads on the website or user fees.
For stores that don't support that use GPS to determine the store and try to send a list of items that the store has (scrape website?).
Does a website like this exist?
Wednesday, October 17, 2007
Tuesday, October 09, 2007
Form post with URL paramters (after question mark)
and used JavaScript to set the action and call submit. But Tomcat showed the request as a GET. I found that adding a dummy form input fixed the problem:
<form name="doForm" action="" method="post">
</form>
<form name="doForm" action="" method="post">
<input type="hidden" name="blah" value="blah"/><!-- need at least 1 input or the form uses method="get" even when "post" is specified. -->
</form>
Exception plan
Thursday, October 04, 2007
Subversion notes
- I wish cvs2svn converted .cvsignore files to svn:ignore properties.
- I wish it handled tags and branches natively instead of using the copy method. Tags and branches are core parts of version control and I think something is lost by implementing them non-natively.
- I hope svn:externals will be able to point to a specific file soon.
- I wish update and status didn't print so much extra info about the externals. For status I have to run
svn status --ignore-externals --show-updates %* | grep -v "^[XI]" | grep -v "^Status against revision"
just to get what I want.
Tuesday, October 02, 2007
Converting .cvsignore file to Subversion svn:ignore property
#!/bin/bash
find . -name ".cvsignore" -print | sed "s/\/.cvsignore//" | tee ignoredirs.txt
for i in `cat ignoredirs.txt`
do
echo Processing $i/.cvsignore
svn propset svn:ignore -F "$i/.cvsignore" "$i"
svn remove "$i/.cvsignore"
done
Friday, September 28, 2007
Garbage collecting file system
Google has done that See section 4.4 (page 8) of http://209.85.163.132/papers/gfs-sosp2003.pdf
Subversion: Setting svn:keywords property
#!/bin/bash
echo Seaching...
# Put Keywords up one directory so the 2nd-last greps don't search it.
grep -R -H "\$Date:" * | grep "\$Date:" > ../Keywords.txt
grep -R -H "\$Revision:" * | grep "\$Revision:" >> ../Keywords.txt
grep -R -H "\$Author:" * | grep "\$Author:" >> ../Keywords.txt
grep -R -H "\$Id:" * | grep "\$Id:" >> ../Keywords.txt
echo Setting Properties...
cat ../Keywords.txt | sed "s/:.*$//" | sed "s/^/\"/" | sed "s/$/\"/" | xargs -L 1 svn propset svn:keywords "Date Revision Author Id"
echo Results:
svn status
Tuesday, September 25, 2007
Remove empty Subversion directories
#!/usr/bin/bash
for i in `find . -type d -print -name ".svn" | grep -v "/\.svn"`
do
if [ -z "`ls -A $i | grep -v '\.svn' `" ]
then
echo Removing $i
ls -A $i
svn remove $i
fi
done
echo Results:
svn status
Update:
The script above doesn't handle spaces in the filename so use the following two scripts if you have spaces in any filename:
svnPrune.sh
#!/bin/bash
echo Searching...
find . -type d ! -path "*\.svn*" ! -name "\." ! -name "tags" ! -name "branches" -exec /svn/svnPruneDirectory.sh {} \;
echo Results:
svn status
svnPruneDirectory.sh
#!/bin/bash
directory="$*"
#echo Processing $directory ------------------------------------------------------
files=`ls -A "$directory" | grep -v '\.svn'`
#echo files=$files
childrenCount=`ls -A "$directory" | grep -v '\.svn' | wc -l`
#echo $directory: $childrenCount
if [ "$childrenCount" -eq "0" ]
then
echo Removing $directory
# echo $files
svn remove "$directory"
fi
Monday, September 24, 2007
Terminal window with 3 frames
- Output frame (At the top): Shows all program ouput and input/commands that the have been processed.
- Input frame (in the middle): Allows the user to enter standard input. Only show when a program is waiting for standard input.
- Command frame (at the bottom): Allows the user to enter commands.
- It would be obvious when I wrote a command that is waiting for user input.
- It could allow you to provide standard input via a command after running another command.
What do you think? Does something like this exist?
Friday, September 07, 2007
Java applet to check Java version
JavaVersionCheck.class:
import javax.swing.*;
/**
* Prints the <code>message</code> if the java version doesn't match
* <code>javaVersionPattern</code>.
* @author James Stauffer
*/
public class JavaVersionCheck extends JApplet {
public void init() {
try {
String javaVersionPattern = getParameter("javaVersionPattern");
String message = getParameter("message");
if(VersionMatches(javaVersionPattern)) {
add(new JLabel(message));
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static boolean VersionMatches(String javaVersionPattern) {
String javaVersion = System.getProperty("java.version");
return javaVersion.matches(javaVersionPattern);
}
public static void main(String args[]) {
if(args.length > 0) {
String javaVersionPattern = args[0];
if(VersionMatches(javaVersionPattern)) {
if(args.length > 1) {
System.out.println(args[1]);
} else {
System.out.println("Matches " + javaVersionPattern);
}
}
}
}
}
HTML:
<applet height="30" width="300" code="JavaVersionCheck.class">
<param name="javaVersionPattern" value="^1\.4.*">
<param name="message" value="Java 1.4 is not supported. Please upgrade to 1.5.">
</applet>
Friday, August 10, 2007
toString() cost
Thursday, August 02, 2007
Dynamic/static language
String str = "Hello";
var temp = str;
temp = 10;
1. Would that be possible?
2. Would that be beneficial?
Wednesday, June 27, 2007
Debugger for *nix pipe commands
As I build *nix piped commands I find that I want to see the output of one stage to verify correctness before building the next stage but I don't want to re-run each stage. Does anyone know of a program that will help with that? It would keep the output of the last stage automatically to use for any new stages. I usually do this by sending the result of each command to a temporary file but it would be nice for a program to handle this.
Monday, June 25, 2007
Tuesday, May 22, 2007
Programming Trends
Friday, May 18, 2007
Telecommuting tips
- Practice communicating by email (especially when it is easier to talk in person about something) so you get better at writing emails that are complete and easy to understand.
- Practice doing as many normal activities on your telecommuting days as possible. Minimize "waiting until you get back to the office".
- Practice minimizing differences between your telecommuting and in-office days so that your telecommuting doesn't negatively affect the company.
Monday, May 07, 2007
Method return values for null objects
For a List the null return values might be:
get(int) : null
size() : 0
iterator() would be an empty iterator
That would allow the following code that has less null checks.
List items = null;
if(something) {
items = ...
}
for(int index = 0; index < items.size(); index++) {
Object obj = items.get(index);
}
Friday, March 30, 2007
Automatic casts
List list = new ArrayList();
list.add("one");
list.add("two");
for(Iterator i = list.iterator(); i.hasNext(); ) {
String item = i.next();//Automatic casts
System.out.println(item);
}
//Or using the new for construct:
for(String item : list) {
System.out.println(item);
}
http://weblogs.java.net/blog/emcmanus/archive/2007/03/getting_rid_of.html shows that the compiler can get really close. Why can't it go the rest of the way?
Friday, March 16, 2007
IDE freedom
Do you think that is a fair way to evaluate?
Friday, February 23, 2007
Cygwin ssh and key files
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@The problem is that chmod wouldn't actually change the permissions so I couldn't get past this problem. When I searched on this I found refernces to turning StrictMode off but that didn't work for me can caused errors.
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '//turfclub/users/jstauffe/.ssh/id_rsa' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: //turfclub/users/jstauffe/.ssh/id_rsa
To fix this I did the following:
- Started my bash shell
- mkdir /home
- mkdir /home/.ssh
- cp ~/.ssh/* /home/.ssh
- chmod 600 /home/.ssh/*
- mv ~/.ssh ~/.ssh.bak
- cd ~
- ln -s /home/.ssh
It now works great (even in the normal Windows shell)!
Wednesday, January 17, 2007
Automatic casting
list.get(0)
would automatically be casted to the type of the variable hi
.
List list = new ArrayList();
list.add("hi");
String hi = list.get(0);
I know that generics allow you to reduce casting but they do so at the expense of making declaration more difficult. To me, the benefit of generics is that they allow you to have the complier enforce more rules -- not they they reduce casting (but I haven't used them much so I am somewhat uninformed). This proposal would only reduce the amount of code to type, not move it to another place.
Tuesday, January 16, 2007
Who has changed the most lines in cvs?
cvs annotate > annotate.txt
rem remove the portion before the name
sed "s/^[0-9. (]*//" annotate.txt > annotate2.txt
rem remove the portion after the name
sed "s/[ ].*$//" annotate2.txt > annotate3.txt
sort annotate3.txt > annotate4.txt
uniq -c annotate4.txt > annotate5.txt
Monday, January 15, 2007
Tip: Need to communicate between anonymous inner classes?
Do you have two anonymous inner classes that need to communicate? I had two anonymous inner classes that implemented Runnable and needed to communicate with a boolean value. Therefore I decided to make a boolean variable in the declaring method but in order for the inner class to access the variable it needs to be declared final. But that would prevent me from changing the variable! I needed a mutable Boolean. Instead of creating a MutableBoolean class I declared the variable as "
final boolean[] done = new boolean[]{false};
" so that one thread could call "done[0] = true;
" and the other thread could check "if(!done[0])
". If there is a better pattern for this please tell me.Background of why I needed this:
In an applet, I was saving data back to the server. In order to keep the UI responsive I of course do that in a separate Thread from the Event Distpatch Thread. When I save the data I first send then data and then read the response so the user only really needs to wait for the data to be sent. Therefore I have a timer that tells the user that they don't need to continue waiting after they have waited 30 seconds. But I don't need to pop that if the response is already read so I needed a way for the reader thread to tell the timer message Runnable that it was already done. I actually found a better solution: The reader thread can call stop on the Timer so that it is never run.