BibleGateway.com Verse Of The Day

Thursday, February 28, 2008

Anticipation is Worse Than Real Thing

Well, they say the anticipation and waiting is harder than the actual event, for example waiting for a dental procedure or something like that. They're right -- 2 of my recent stresses have been relieved in the past two days, and all the fretting has been for nothing.

My truck passed NYS inspection without even needing so much as a windshield wiper blade. I was worried about the rear brakes, since the front ones were in such bad shape when I did them last month (needed new pads, new rotors, and on one side I ended up replacing the whole caliper and shearing off a banjo bolt, but that's another story). Getting the brakes replaced would have cost a butt load of cash we just don't have right now.

Then yesterday we finally got our act together and did our taxes. The big nagging fear, no matter how much math you do throughout the year, is that all of a sudden we owe the government butt loads of cash we don't have. Nope, we're still getting a return -- nothing too elaborate, but at least we're not paying.

Goes to prove another saying right -- "Procrastination is a lot like masturbation. It feels good while you're doing it, but in the end you just screw yourself".

Monday, February 25, 2008

FCKeditor - Embedded HTML Editor

For a recent project, I wanted something fancier than a regular HTML text area to allow user input with formatting. "Something like the editor on Blogger", I thought.

After hitting Google, I ran across FCKeditor. I had heard of it before, and even played with the demo once, but never did anything with it. Never had much of a reason to. Today that all changed.

After reading through the Developers Guide, I downloaded the ZIP, unpacked into my public web directory, and had it working in no time. In less than 30 minutes, I had the FCKeditor completely tied into an existing Rails form, replacing a boring old text area. After a few minutes of testing inserts and updates, and some cross-browser testing with Firefox and Internet Exploiter, I was happy.

There were only a few lines of JavaScript code to add to the page, and those are all spelled out in the Developer's Guide, so I don't feel the need to repeat those here.

Overall, I was pleasantly surprised. Unlike a lot of open source projects out there, this was extremely easy to get started with, easy to install and embed into existing applications, and the documentation was pretty good for a change. The quality so far has also been nothing short of impressive. (the editor is more full-featured than the one Blogger uses.)

It's licensed under the GPL, LGPL, or MPL (your choice), and can be embedded in any project, open source or commercial. Also, in addition to the JavaScript version I used today, there are versions for JSP, ColdFusion, PHP, Python, etc.

This project today was just a personal side project, but I think FCKeditor might find it's way into my arsenal for work projects as well.

Thursday, February 07, 2008

Reading And Writing Text Files in Ruby

On a recent project, I had everything automated up to the point where I had to give feedback to the business analysts on what, if any, of their data had to be fixed and re-run.

I ended up writing some Ruby scripts to run through a file of transaction responses, and sort out the various error types into separate files, and produce a summary report of the error counts in each category.
Now the only manual part was cutting and pasting the summary into an email, and attaching the various sorted files.

I was pleasantly surprised at how easy it was to read and write text files in Ruby. Let's say you just want to read a text file, line by line, and spit it back out, a la "cat"...
File.new(filename, "r").each { |line| puts line }
Wow, that was easy, eh? Let's try reading that file into an array for use later...
results = []
File.new(filename, "r").each { |line| results << line }
Let's say you want to capitalize everything in the file, and spit it out to a new file...
out_file = File.new("upper_case.txt","w")
results.each do |line|
out_file.puts line.upcase
end

That was easy. It's probably obvious, but the first argument passed to the File constructor is the filename, and second is the read/write flag.

For comparison' sake, let's read a file in Java and spit it out line for line...
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
...
BufferedReader is = new BufferedReader(new FileReader(fileName));
String line = "";

try {
while (line != null)
{
line = is.readLine();
System.out.println(line);
}
catch (Exception e) { /* do nothing for now */ }
finally
{
try {is.close();}catch(Exception f) { }
}

Definitely not "hard", but it is a bit more code. Writing a file is very similar, except of course you use FileWriter and BufferedWriter instead of FileReader and BufferedReader, and write to the file instead of reading from it.

I'm not really trying to prove anything here -- Ruby isn't better than Java, Java isn't too hard or too verbose, etc. I like Java. I like Ruby. Against my better judgment, I even like Oracle, but that's another topic. I just found that working with files was easier than I expected, even for a Ruby beginner like myself.

Tuesday, February 05, 2008

Funny Thing About Taxes

The other day Woot.com's product description included a funny little rant about taxes....

"The worst thing about taxes is that you’re supposed to compute the total yourself. What if you ate at a restaurant and when you said hey, what do I owe you? They said you figure it out. And you thought about what you’d eaten and said well, I guess that’d be about $7.25, and they said no, it’s $11.40. Plus now we’re going to charge you an extra three bucks for trying to cheat us. If they knew what you owed them, what was the point of making you figure it out? Just to be jerks, probably. Or maybe in hopes you’d miss high, which is basically how taxes work."