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

Back here at the devdaily.com world headquarters I've been working on fixing some "issues" on this blog, and one of the minor things I just worked on was finding a new icon for my RSS news feed. It turns out there's a lot of free RSS Feed icons out there in the world, you just have to google them, then follow tons of links.

A list of free "RSS Feed" icons

If it will help save anyone the trouble, here are the best RSS Feed icons I found today, in sorted order, starting with the ones I think are best.

It's been a long time since I worked on an old-school JSP (without the benefit of a framework like JSF or Struts), but I've wanted to add alternating row stripes ("zebra stripes") to some HTML tables in some old JSP's for a long time. I like tables with zebra stripes because they're easier to read, so now that I have some free time, I finally got this done.

Now that I have all of my JSP/CSS code working properly, I thought I'd share it all here in the form of a "recipe".

When Doug Bowman left the Google design team, he didn't leave quietly. He wrote two blog entries about his reasons for leaving (Goodbye, Google, and Hello, Twitter).

My favorite business book of all time is "Growing a Business" by Paul Hawken, and in the book he shares the following mission statement (from a company whose name I won't mention here) as something you probably don't want to write:

This article is now part of my new eBook, which is only $2.99 on Amazon.com:

You want me to do what? A Survival Guide for New Consultants

I hope you enjoy my book, and more than that, I hope it helps you have a very profitable and rewarding career.

 

This article is now part of my new eBook, which is only $2.99 on Amazon.com:

You want me to do what? A Survival Guide for New Consultants

I hope you enjoy my book, and more than that, I hope it helps you have a very profitable and rewarding career.

 

Problem: You have an array of elements, and you need to process every element in the array, except the elements that match a given regular expression (pattern).

Solution: You can solve this problem using a combination of the Perl regular expression pattern matching, along with the next operator.

Perl for loop FAQ: What is the Perl for loop syntax? (Also written as, "How do I perform some type of operation on every element in a Perl array?)

Perl has a nice "for loop" syntax that lets you iterate through each element in an array, and perform some operation on each element.

Here's a simple Perl for loop example where I first create a small array, and then use the for loop to print each element in the array:

Ruby substring FAQ: I can't find a Ruby substring method, how can I tell if one Ruby string contains another string?

Solution: I expected the Ruby String class to include a method named substring, but it doesn't. My personal disappointment aside, it does have a method named include? that works the way I expected it to. Here's a simple example, using the irbenvironment to perform a few tests.

Ruby character/string FAQ: How can I loop through each character in a Ruby String, and perform some operation on each character?

I'm currently using Ruby 1.8.6, and you can use the Ruby each_char method if you'll first require the jcode module. To be clear, this code will not work in Ruby 1.8.6:

a = 'hello, world'
a.each_char { |c|
  puts c
}

In fact it results in the following error:

Problem: You need to loop through each character in a Ruby String, and get the byte value of the character as you iterate through the characters in the String.

Solution: Just use the each_byte method of the String class to loop through each byte in your String, like this:

a = 'hello, world'
a.each_byte { |c|
  puts c
}

This results in the following output:

This article is now part of my new eBook, which is only $2.99 on Amazon.com:

You want me to do what? A Survival Guide for New Consultants

I hope you enjoy my book, and more than that, I hope it helps you have a very profitable and rewarding career.

 

Software healing component #3: The self healing program

In the first two parts of this tutorial I wrote about a worker program, and the functionality it needs to provide to support a self-healing architecture. In the second part I wrote about an open source program named Nagios, which can be used to monitor your worker programs. In this third part of the self-healing recipe, I will now write about what is necessary for the "healing" component.

Component #2: The software monitoring program

The second piece of the self-healing architecture is to have a program that monitors your worker programs. You can write your own software monitoring program, as I did many years ago, but that's pretty old-school, and frankly, not a good idea any more.

Problem: When working with some Ruby code in an irb session, I just got the following error message:

NameError: uninitialized constant Tempfile

Here's a snippet of my irb session where this error occurred:

>> tmp = Tempfile.new
NameError: uninitialized constant Tempfile
	from (irb):1

Solution

This "NameError: uninitialized constant" looks intimidating, but it's actually not a big deal: I just forgot to require the tempfile package.

Problem: There are times when you're writing Ruby code that you need to be able to create and write information to a temporary file. If you write your own code to do this, there are a number of decisions to be made (see below), and you'd like to avoid all of that mess.

Solution: Use the Ruby Tempfile class to handle the grunt work for you.

Ruby file FAQ: How do I append text to a file in Ruby?

Solution: Appending text to a file with Ruby is similar to other languages: you need to open the file in "append" mode, write your data, and then close the file.

Here's a quick example that demonstrates how to append "Hello, world" to a file named myfile.out in the current directory:

Ruby file FAQ: How do I write to a file in Ruby?

Writing to a file with Ruby

Many times when you're working with Ruby scripts you need to be able to write text information to a file. Writing text to a file with Ruby is reasonably straightforward. Just like many other languages, you need to open the file in "write" mode, write your data, and then close the file.

Ruby current date/time FAQ: How can I determine the current date and time in a Ruby script?

You can create a Time object in Ruby to represent the current date/time by calling the Time.now method, like this:

There are quite a few ways to open a text file with Ruby and then process its contents, but this example probably shows the most concise way to do it:

# ruby sample code.
# process every line in a text file with ruby (version 1).
file='GettysburgAddress.txt'
File.readlines(file).each do |line|
  puts line
end

As you can see, this example code is very concise, and inside the processing loop you can do whatever you need to do with the line variable.