How-To

CDATA Section Delimitosis

Delimitosis = disease pertaining to delimiter

I don't know if it is just because I am a parser-minded person, but the first time I learned about CDATA Sections a warning buzzer went off in my head and has been ringing ever since. It is saying: What if ]]> happens to be in the data you put into a CDATA Section?

Well obviously it is not allowed. Hmmm. But that is not very helpful is it? Does than mean I am supposed to check to see if my text contains ]]> every time I want to use a CDATA Section? And what should I do if it does?

I want to settle some of the unsettling issues about CDATA Sections here.

Internationalization (i18n)

In order to offer localized versions of an application, there are two things to be taken care for:

  • Internationalization (i18n): this is more development centric and it's all about designing your application to support translations, foreign character sets, timezones, different number / currency / date formats etc.
  • Localization (L10n): using the mechanism provided by i18n, this includes the actual translation and settings for a new language.

On this article I focus mainly on the translation part of the i18n process, although many other subjects are touched.

Dreamweaver 8 as a Ruby IDE

In last week's post, I talked about how I was trying to find a suitable IDE for Ruby on Rails development, and how my preferred solution would be a syntax highlighting plug-in or modification for Dreamweaver or Visual Studio.

I also provided a link to this tutorial from BDC Software, which implied that with a bit of tweaking, Dreamweaver could not only do the syntax highlighting, but even code hints too. I tried it, and it worked, so the rest of this post is a step by step process for both, which borrows an awful lot from that tutorial, and from this page from RubyGarden.

A Little More on Rails

Last week I started talking about giving Ruby on Rails a try, and I had planned to have plenty more to say for this post. I have a printed copy of the great looking Four Days on Rails guide sitting on my desk, and I’ve been looking forward to digging in.

Unfortunately, aside from a minor quest to figure out how to customize IDE syntax highlighting, the experiment took a bit of a backseat this week. So, I’m going to go back to what I learned the previous week and share something from the starter tutorials that really got me excited about working with the framework.

How I Invented Base64

Base64 is a way of storing any data as plain ASCII text. It looks like this:

LZPVtzlndhYFJQIDAQABMA0GCSqGSIb3DQEBAgUAA1kACKr0PqphJYw1j+YPtcIq
iWlFPuN5jJ79Khfg7ASFxskYkEMjRNZV/HZDZQEhtVaU7Jxfzs2wfX5byMp2X3U/
5XUXGx7qusDgHQGs7Jk9W8CW1fuSWUgN4w==

Look familiar? You'll see it in your e-mail source when your e-mail has attachments. How did I invent it? Well I didn't really, but before I knew base64 I came up with an encoding system I called "6-bit rollover" that turned out to be nearly identical to base64. It turns out that was not a momentous achievement because the beauty of base64 is how natural and simple it is. Here I am going to show how sensible base64 is by describing my discovery process, and giving you the quick round-up of everything you need to know to use base64.

EBCDIC to ASCII (and SBCS) Conversion

The first task I had when I got a C programming job in 1991 straight out of college was a small two week project writing a program to convert EBCDIC to ASCII. The software company I joined had about 10 employees and a consultant named Sam. The owner of our company wanted to do this cheaply as a favor to the customer and hoping for a bigger contract down the road, so I think mostly only my hours were charged on the contract even though it was really just Sam mentoring me. Sam took me over to meet the customers at their site and ask some more questions about the data we were converting. My memory is that they were very nice but they could not give us any more information or sample data!

It can be hard to figure out the encoding (and the variant of the encoding) but once you get the mapping right implementing the conversion efficiently is easy for single byte character sets. Here I take the EBCDIC to ASCII example through these stages and finish by trying to emphasize that it is a crying shame when charset conversion is not extremely fast.

Quack Quack

One of the popular aspects of Ruby is the concept of "Duck Typing". It's a powerful aspect of the language that, once understood and utilized, shows the uniqueness of the Ruby type system.

One example I like to use when demonstrating what duck typing is to demonstrate this pseudo Ruby-code:

int someFunction(blah)
{
  if(blah.class == String) return blah.to_i
  elsif(blah.class == CustomClass) return blah.convert_custom_class_to_int
  elsif(blah.class == AnotherClass) raise "Can't convert AnotherClass to int!"
}

The above code shows a (poor) implementation of trying to do certain actions based on the class of the object. But why? What happens if we create new custom classes - then we have to go back and update this function to handle them. What we create a new String based class that has all sorts of new funky features. This doesn't fit into this model very well, either. Why not just do this:

That Ol' OEM Code Page

If you have a regular U.S. or Western European (Windows-1252) system locale code page, try this:

  1. copy and paste these 4 characters ÂÄÒÙ into notepad
  2. save it as oem.txt
  3. open a DOS window and cd to the directory where you saved it
  4. enter: type oem.txt

Do you see ┬─╥┘ instead of ÂÄÒÙ? Why? That is because your system local "ANSI" code page is different than your DOS "OEM" code page.

Using UUID/GUID as Primary Key in Rails

A project I'm working on has a difficult requirement to meet. It needs to be able to support a multi-master database model. If you're already familiar with the concept, please forgive the following short introduction. This means that multiple systems need to be able to create records in their local database and sync up to other ones later. Connection among the systems is not guaranteed to be up 100% of the time. A prime example of this type of system is Microsoft's Active Directory.

Data Types - PHP Vs. Ruby

In conversation with a fellow PHP person now doing Perl, he asked… how does Ruby do types?? And I thought I knew how to answer him, but then when I opened my mouth I found I didn't have the words.

PHP is not a strongly typed language. You can assign $foo an integer, print it (even though it does not contain a string), assign an array and so on. PHP doesn't care.

However, if you want to be certain of the type in a variable there are a few functions to help you out.

settype($var, [type]);

example, to make sure these types

settype($foo, "bool"); // also could use "boolean"
settype($bar, "int");