September 25th, 2007

Ported my old geek blog’s theme to Wordpress

If you read this blog on the web, you may have noticed that the whole site looks different. I’ve never been too fond of the default Wordpress theme, and didn’t like any of the other Wordpress themes that I’ve seen, enough to use them.

I did always like the theme I had on my old Blogger geek blog, but that theme was not available for Wordpress. The theme is called “Rounders 3″, originally designed by Douglas Bowman.

So, I hacked apart a page from my old geek blog, and did some reading about Wordpress theme development (see links section below), and worked on building a Wordpress theme based my old geek blog’s theme. Today, I decided to go ahead and switch this blog to use that newly-ported theme.

Here are two screenshots, for comparison:
spugbrap’s blog (old theme - default wordpress) [small]spugbrap’s blog (new theme - ported from Blogger to Wordpress) [small]

Useful Links:
Theme Development « WordPress Codex
How-To: Create a Wordpress Theme in 5 minutes

Feedback:
What do you think of the new look? Please feel free to leave a reply, below! Also, if you run across any broken links, unreadable fonts, missing images, alignment problems, etc., please let me know. Thanks!

September 14th, 2007

Regular expressions for converting code-indentation spaces to tabs in TextPad

I’ve never been a fan of using tabs to indent my code; I prefer spaces. Writing code is an art form, and when you use tabs to indent, you can’t assume that it will still look pretty on someone else’s machine, or in another application, etc., since tab sizes are platform-dependent and–although usually user-definable–the default size (typically 8 spaces, I think) tends to be much larger than my own 2-4 space indentation style.

However, some of my co-workers indent with tabs, and others indent with spaces. I’ve found that it’s easier for me to avoid inadvertently messing up existing code when I just bite the bullet and use tabs.

So, what follows are a couple of search/replace regular expressions I’ve recently used in TextPad, to make some existing code more consistent, by converting the spaces to tabs in certain relevant locations.


1. Regular expressions for aligning inline comments with tabs

Find what:   \;( *) {2}(\t*)\/\/
 
Replace with:   \;\1\t\2//

Customization: The number 2, in curly braces (above), should be replaced with the number of spaces that are used for indentation, in the code you’re running this on. In this case, the code was indented in increments of 2 spaces. Sometimes I deal with code that’s indented in increments of 4 spaces, in which case that 2 would change to a 4.

Manner of execution: Run via Replace All, repeatedly, until there are no more matches.

Recommended scope: I used it on a very specific block of selected code. Keep reading for the specific format.

When I used this on a block of code that consisted of variable declarations and //-style comments, it ended up making the comment blocks all line up nicely. Here is an animated GIF1 of a series of screenshots, showing how repeatedly running this expression transformed the comments into tab-indented comments that lined up nicely:

animated progression of screenshots showing comments separated from code with spaces, and eventually just tabs (and all lined up nicely)

I’m not sure how useful this will be, in general, because I think I just kind of lucked out when I got the results that I did. I thought it was worth sharing, though, because it impressed me when it produced results that were better than I had actually envisioned. :)

Two important things to note are:

  • The actual variable declarations (beginning of each line) were already indented with 1 tab.
  • There were a consistent number of spaces between the semicolons ending the variable declarations, and the double slashes starting the comments. While this didn’t help them line up, as spaces, it did make things pretty when the spaces were replaced with tabs.

If you’d like, you can see what my TextPad Replace dialog looked like, so you can see things like which checkboxes are checked, etc. Also, please note that in my TextPad preferences, I have it set to Use POSIX regular expression syntax (as previously mentioned, in another TextPad search/replace expression entry, a couple years ago).


2. Regular expressions for changing leading indentation spaces to tabs

Find what:   ^(\t*) {4}
 
Replace with:   \1\t

Customization: As with the first expression, above, the number in curly braces should be changed to the spacing increment used for indentation, in the code you’re running this on.

Manner of execution: Run via Replace All, repeatedly, until there are no more matches.

Recommended scope: It can be used on a block of selected text, the entire active document, or even on all open documents, if you’re brave and somewhat evil. :)


Footnotes

1 Sorry for using an animated GIF. I’d rather not have something constantly flashing on the page, because it distracts, and resembles an advertisement. I would have preferred another solution, but I racked my brain for over two hours, trying to decide how to present this series of 9 screenshots. I didn’t want to alienate readers who might read this using a feed reader that doesn’t support javascript, and I hate making people click through from the feed to the main site–I strongly prefer full-text rss feeds! Laying the 9 images out horizontally or vertically took up either too much space, or required making the images too tiny to read. In the end, this animated GIF seemed like the best portable way to show the effect I was trying to show. I won’t make a habit of using them, though. :)

[return to top] / [expression 1] / [expression 2]

July 3rd, 2007

SQLException: Charset cp850/Cp850 is not supported by the JVM.

I recently had to reinstall Tomcat on my development server at work, because my previous installation was having major issues for unknown reasons. When I finished installing it, and deploying my webapps to it, I ran into this annoying character set issue (which I was not getting with the previous installation).

I could swear I’d seen this message before, and several of my co-workers thought they recognized it, too, but nobody knew what to do about it. Every time I started the tomcat service, it was spitting out these three stack traces, for every webapp, in my exception log:

Class: net.sourceforge.jtds.jdbc.ConnectionJDBC2
Method: loadCharset
SQL STATE: 2C000
SQL ERROR CODE: 0
STACKTRACE:
java.sql.SQLException: Charset cp850/Cp850 is not supported by the JVM.
[...]

Class: org.apache.catalina.valves.JDBCAccessLogValve
Method: start
EXCEPTION WRAPPER MESSAGE:
[ERROR] ContainerBase.addChild: start:
STACKTRACE:
LifecycleException:
java.sql.SQLException: Charset cp850/Cp850 is not supported by the JVM.
[...]

Class: org.apache.catalina.core.ContainerBase
Method: addChildInternal
EXCEPTION WRAPPER MESSAGE:
[ERROR] Error deploying web application archive [foo].war
STACKTRACE:
java.lang.IllegalStateException: ContainerBase.addChild: start:
LifecycleException: java.sql.SQLException:
Charset cp850/Cp850 is not supported by the JVM.
[...]

NOTE: These stack traces only show the top line and context info, to avoid cluttering up the blog post too much. [View full stack traces here]

To troubleshoot this, I first tried cleaning out all the already-compiled classes/jars from my source code tree, and rebuilding/redeploying all the webapps, but the same behavior continued. Next, I wiped out my whole source code tree, checked it all out from CVS again, and rebuilt/redeployed all the webapps. Still got the stupid cp850 exceptions.

Before, during, and after all of that rebuilding stuff, I spent hours doing web searches on various search engines, tweaking my queries, and not turning up much of anything.

At one point, it seemed like it had to be a problem with my Sybase ASE 12.5 database configuration. I didn’t like the sound of that, though, because it’s much easier to reinstall an app server and redeploy my webapps, than it is to rebuild my database and recreate the necessary test data.

I thought maybe our build script wasn’t deploying the right versions of all the jars that needed to be deployed, so I slowly started copying the jars from my backup of my previous tomcat installation, and copying all the configuration files, and so forth. Eventually, my entire tomcat directory tree had been replaced with the backed-up tomcat installation, but the evil cp850 exceptions still lingered!

Now it was *really* looking like a database issue! I searched all the files on the machine for ‘cp850′ (case-insensitive search), and turned up nothing useful. When I searched the windows registry, I found one thing that was intriguing:

KEY: HKEY_LOCAL_MACHINE\
SOFTWARE\SYBASE\Server\
[MyServerName]_BS\Parameters\
VALUE NAME: Arg5
VALUE TYPE: REG_SZ
VALUE DATA: -Jcp850

I asked my co-workers to check their registries, but they had the same thing, and their servers were behaving just fine. Besides, this was just the backup server (BCKServer), not the actual SQLServer. So that was a dead end.

I poked around for a while longer, and *finally* figured out that it was the JVM that the Tomcat service was configured to use. When installing it, I had chosen the default JVM that it had selected, because it looked right.

The installer defaulted to the JVM that was installed with the Java plugin for web browsers and such:
C:\Program Files\Java\jre1.5.0_06\bin\server\jvm.dll

But I needed to use the one that was installed with the JDK I compiled with:
C:\Program Files\Java\jdk1.5.0_06\jre\bin\server\jvm.dll

I believe the reason for this is because when I downloaded the JDK, it either only came in one package, which included international support, or I happened to choose the package that included international support. For the Java plugin download, though, I must have selected the US/English-only package, because it was smaller or something.

That was a nightmare to track down, and I hope that by posting this, I can save someone else the time and trouble!

July 2nd, 2007

Developers embed Pro-Firefox/Anti-IE sentiments in their code

As a professional web application developer, I’m well aware of the challenges involved in coding for multiple browsers (and, even worse, older/buggier versions of those browsers). I also hate it when a website won’t behave the way I want it to, so I often end up viewing the source with FireBug, then messing around with the code.

If I just need to “fix” it on a one-time basis, I’ll just edit it with FireBug, but if I need it to behave better every time I visit the site, I’ll write a GreaseMonkey script (Incidentally, I use Platypus to generate a lot of my GM scripts. So easy!).

Sometimes, in the course of viewing/hacking up their code, I run across funny things that developers left in there. Here are a few of them that I’ve run across, which express the designers/developers’ browser preferences.

From viewing the source of a last.fm page:

<span class="iesucks" style="display: block">&nbsp;</span>>

[I just liked their css class name]


A friend sent this next one to me a couple months ago. I went and tried it, at the time, and I got the error message. But they seem to have fixed it since then. Anyways, this online icon maker page, when viewed in IE, would throw a javascript error when you moved your mouse over the editor component on the page.The funny part was the error message:

'shitty_IE_needs_this' is undefined

Ooh, I just noticed that this site was featured on my favorite geek humor blog, Worse Than Failure (formerly known as The Daily WTF). They’ve got a screenshot of it, so you can still see how silly it looked.


This last one was not found in source code, so it may or may not have been written by developers, but it sounds to me like it was. From Google Reader’s FAQ (bold/italics added for emphasis):

15. What are Google Reader’s system requirements?

For the best user experience, Google Reader requires an up-to-date browser. We recommend that you use Firefox (download: Windows Mac Linux) or Safari (download: Mac), but Internet Explorer will work too (download: Windows).

March 30th, 2007

The difference between introspection and reflection in Java

I haven’t used any of the fun introspection/reflection stuff in Java for quite some time, so I got confused about terminology, recently. I kept using the words introspection and reflection interchangeably, but it sounded wrong/made me feel stupid every time I did. A quick Google search provided me with a concise explanation of the differences.

From Java Tip 71 on javaworld.com:

One question that is asked often is, What’s the difference between introspection and reflection? The answer: Reflection allows you to find out which members an object has; and introspection allows you to identify which (JavaBean) properties an object has. That’s why the java.lang.reflect lives in a separate package, and the Introspector object is in the java.beans package. Links to these packages on Sun’s Java site, as well as further information on JavaBeans, are available in the Resources section below.

The key things to recognize are:

  • reflection can be done on any class
  • introspection provides additional info about JavaBeans