Scala, Java, Unix, MacOS tutorials (page 398)

Glassfish JDK path problem: Some time ago I downloaded Glassfish, and then got away from it for a while. Today when I tried to run this command

C:\glassfish\bin> asadmin start-domain domain1

I got this error message from Glassfish:

Having just downloaded and installed vim (gvim) on my Mac (Mac OS X 10.5.x to be precise), and then struggling for a while to set the default font, I thought I'd make a brief note here about how to set the default font properly.

Setting a default gvim font in the gvimrc file

To set a default font for the gvim editor (in my case on Mac OS X), edit a file named ~/.gvimrc (i.e., a file named .gvimrc in your home directory), and add this line to get a 12-point Monaco font:

I just finished downloading and installing vim (gvim) on my Mac (Mac OS X 10.5.x to be precise), and then struggling for a while to set the default colorscheme, I thought I'd make a brief note here about how to set the default colorscheme properly.

Setting a default gvim color scheme (colorscheme)

As a friend of mine once, said "It's easy to do, once you know how to do it." For me, that applies to setting a default colorscheme for gvim on Mac OS X.

To set your vim default colorscheme to a theme named "slate", just follow these simple steps:

Wow, I just realized that until this morning I hadn't done anything new with Ant in several months. It sure is nice when things just work. :)

Funny, this seems about five years late, but using Java, if you want to get the HOSTNAME on Windows Server 2003 (and possibly any version of Windows 2000), you have to do a little extra work. The environment variable you need to access on those versions of Windows is referred to as COMPUTERNAME, so in my case, since my software is going to be running on a lot of different (and currently-unknown) computer systems, I created a little convenience method to handle this problem.

A perl function that runs a Unix command and returns its exit status

Here's the source code for a Perl function I created this morning. The purpose of this function/method is to run a specific Unix command, and then return the Unix exit status of that command. As usual with Unix and Linux systems, a zero exit status indicates success, and a non-zero exit status indicates some type of problem.

Without any further ado, here's the source code for my Perl function:

Apple does a lot of things very well, but one area I think they struggle with is mice and keyboards. Historically they've tried a ton of different things with mice, but today's topic is: Why does the Apple wireless keyboard have a layout that's different than a standard keyboard? As Steve Jobs might politely say, WTF?

Here in Louisville there's a local weatherman who has been doing the weather for at least 30 years. One morning last week I was struck by how much he's just "phoning it in" these days.

I can't help but wonder if Barnes & Noble is in financial trouble. I've been a "member" for a while now, and when I used to receive an email once a week I thought we had a reasonable, casual relationship. But over the last few weeks B&N has turned into a stalker, sending me at least one email message every day, with each message sounding more and more desperate: "We'll give you 10% off", "Make that 20%", "No, wait, 40% off".

Life never ceases to amaze me. In this case, one day I write a rant about a Pigpen Developer who is anti-YAGNI, and then later in the week this exchange takes place.

Thursday morning, a customer tells me "Al, we're not going to need the XYZ functionality after all."

"No problem", I say, "I'll delete it."

"That would be great", they say, and I go off and delete all the code related to XYZ.

Today I dug into someone else's project to help fix it, and when I got to the part about sending email messages from within the program, I kept getting this JavaMail API exception:

I just learned by accident today how to control the iPod portion of your iPhone without turning the iPhone on. With your iPhone off, just double-click the Home button, and a visual control comes on screen that lets you play, pause, fast-forward, rewind, and control the volume of your iPod music, with no need to slide the unlock bar on your iPhone.

[toc]

A lot of times I'm asked about software best practices, but sometimes it's easier to show a best practice by showing its opposite -- a "worst practice". With that, today I introduce you to a worst practice I call "The Pigpen Developer".

Okay, this is one small step for me, and not really any steps for mankind ... I never know how to get help on Windows/DOS commands. I try command line options/switches like -h, -help, --help, /help, and \help, and of course none of them works.

Then somehow today I learned that the magic incantation, er, command line option, is /?, like this:

taskkill /?

Duh.

 

I'm not going to describe this much today, but here's the source code for a Java class I put together from a number of other sources on the internet. In short, this code uses a Java Socket to connect to a port on a remote server, sends a command to that server to be executed, and then reads the output from the command that is executed. As a result, I assume that all information sent is text (nothing binary).

Today I needed a Java method to remove all the blank characters from a String. I started to write some code with a StringBuffer or a StringBuilder, then thought there must be some other way to do this. It’s not that the StringBuilder/StringBuffer approach is hard, but just that someone must have already solved this problem.

If you ever need to determine what directory your Java code is being run from (essentially the current working directory), you can get this information from the system properties, specifically the System.getProperty or System.getProperties methods.

The following line of Java code shows how to determine what directory your Java application was started in. This information is stored in the user.dir system property, which you access like this:

Here's some sample Ruby source code that shows how to do something with every file in a directory, where you only work on filenames that match a pattern you're interested in. For example, in my case I'm only interested in processing files that end with the filename extension WMA, so this first snippet of Ruby code shows how to print out the name of each file in a directory with the WMA extension:

I know some of the following features are available through third-party iPhone apps, but I'd still like to see them as standard functions in a new iPhone software release:

A lot of times when you're using Perl you have a list (or array), and you need to search that list for all strings that match a certain regular expression pattern (or regex). Fortunately Perl is built for this type of work, and it's straightforward to (a) perform this search, and (b) put your search results in another list.