5 sins of ruby
By Justin Silverton
Introduction
Ruby has become more and more popular over the past couple of years. This month, I decided to start coding a few smaller apps to see if there was something I was missing. The following are a few issues with ruby that I feel need to be changed, before it really becomes a mainstream language.
1) Horrible syntax
It looks like a mix between Visual Basic and Pascal. I can’t imagine coming back to a large project with hundreds of files and functions and trying to keep everything organized. It would be even worse coming back to a project that someone else created.
2) missing/lacking documentation
Most popular languages are documented very well. For instance, you can go to the main php website and find out how to do pretty much anything (in english or almost any other language). Ruby’s documentation is available, but needs a lot of work to help out developers that are learning the language.
3) slow
Ruby is noticeably slower than other interpreted languages. I am not the only one that has seen performance issues. More on this can be found here. Jruby, a pure-Java implementation of the Ruby programming language, might help increase execution speed.
4) lack of libraries
Just searching google for ruby libraries or extensions doesn’t return many results. This also might be because it is a relatively new language compared to much older languages such as Java or PHP.
5) poor unicode support
Although there are Third party libraries that enhance ruby unicode support, it should be built into the language itself.
11 commentsHow to store large amounts of data in Firefox
by Justin Silverton
For most web applications, there are a couple of different options available for storing data on the client (within the web browser).
Flash allows the storage of up to 100 KB/domain without any user security prompts. The data being stored is accessible across the user’s Flash Player instances, loading stored data into Internet Explorer, Firefox, or any other browser that supports it.
Cookies are another option. A cookie stores user data across multiple browsing sessions. They are limited to 4 KB of storage per domain and are a good way to store user data for convenience or tracking. Web browsers contain cookie and privacy management features to wipe away stored cookies and their stored data and therefore have limited utility for continued persistence. Cookies are sent along with every request on a given domain, adding onto every message exchanged between an end-user’s browser and your site, even if the cookie data is only occasionally used.
Firefox has the ability to store an unlimited amount of data using DOM storage (This may be limited in future versions greater than 2.X).
Here is an example of how use DOM storage:
<script type="text/javascript">
//for security, this must be set to your domain
var storage = globalStorage['yourdomain.com'];
var pageCount;
function setItem(key,value) { //store an item
storage.setItem(key,value);
}
function getItem(key) { //retrieve an item and display it
alert(storage.getItem(key));
}
function removeItem(key) { //remove an item
storage.removeItem(key)
alert("Key:" +key +" was removed.");
}
</script>
Here are some other options that can be used with the globalStorage object:
- globalStorage[’developer.mozilla.org’] - All web pages within the developer.mozilla.org sub-domain can both read and write data to this storage object.
- globalStorage[’mozilla.org’] - All web pages with the mozilla.org domain can both read and write to this storage object.
ajaxwindows: the next big thing?
By Justin Silverton

A virtual operating system in Ajax is an interesting idea. Although it can’t completely replace a desktop operating system, it can allow you to access your documents and files from anywhere.
Ajaxwindows allows you to do the following:
- Backup your files, music, and pictures with one click.
- Display, edit, and save popular file formats.
- Access your data remotely.
Some cool features
- Firefox and IE support - Both Internet Explorer and Firefox are supported. (An activeX control needs to be downloaded for it to work with IE)
-
synchronize desktop wallpaper, IE/firefox favorites, windows startup sounds, windows shutdown sounds, “my documents”, “my pictures”, and outlook express contacts.
-
Change the Theme/Desktop wallpaper (many built-in themes/wallpaper available).
-
Store files using your gmail account. This is an interesting feature. An email is sent to your gmail account with the file as an attachment.
-
The ability to add remove programs/widgets.
Conclusion
Overall, I was impressed with ajaxwindows. However, I did did get the following error a few times when I was within Firefox (IE also crashed whenever I tried to logout):
How to password protect a web directory
by Justin Silverton
This article will show you how to password protect a directory using the apache web server and a .htaccess file.
.htaccess file
The .htacess file should be in the directory that you would like to protect (everything below this directory will also be password protected).
AuthName “Password Protected Area”
AuthType Basic
AuthUserFile /full/path/to/.htpasswd
Require valid-user
Replace “Password protected Area” with the name of the area that you would like to protect. Also, the path needs to be changed to the path of the .htpasswd file (which will be explained further).
Generating a .htpasswd file
A program comes with apache for generating a .htpasswd file. Here is how it works:
htpasswd [ -c ] [ -m | -d | -s | -p ] passwdfile username
htpasswd -b [ -c ] [ -m | -d | -s | -p ] passwdfile username password
htpasswd -n [ -m | -d | -s | -p ] username
htpasswd -nb [ -m | -d | -s | -p ] username password
A full explanation of htpasswd can be found here
If everything is setup correctly you should see the following prompt when you try to access your newly protected directory (and the username/password combo created with htpasswd should allow access):
5 ways to speedup javascript
by Justin Silverton
1) use a compressor
JSMin is a filter which removes comments and unnecessary whitespace from JavaScript files. It typically reduces filesize by half, resulting in faster downloads. It also encourages a more expressive programming style because it eliminates the download cost of clean, literate self-documentation.
PHP version here
2) Minimize the number of .js files
Each .js file reference on a web page means another http request from a client’s browser. Although it may decrease the readability/maintainability of your code, it is faster to have one larger .js file than multiple smaller ones.
3) use profiler and timer tools
Firebug offers a suite of profiler and timing tools that allows you to see exactly how long your scripts take to execute and gives you the ability to tweak and optimize them.
4) asynchronize your code
Browsers run Javascript code synchronously. This means that when a <script> tag has been found, everything on the page stops until the end script tag has been found. If a script doesn’t finish executing within a certain amount of time, then the user gets a warning that says, “A script on this page is taking a long time to complete.”
example:
function testfunc()
{
var x1="test1";
var x2="test2";
alert(x1+x2);
}
testfunc(); //normal way to execute the function
window.setTimeout(testfunc,0); //asynchronous execution of testfunc()
The setTimeout function takes 2 parameters. The first is the name of the function that will be executed and the second is the number of milliseconds to wait until it is called. Since 0 is used for the second parameter, the function is called immediately (it will be forked in the background and the rest of your page will continue to load). This is useful for functions that take a long time to load.
5) cache DOM variables
Every binding in Javascript is late. This means each time you access a property, variable, or method a look-up is performed. Within the IE DOM, this could mean an extensive search of the element to find the same property over and over again, only to be returned to the JScript engine unchanged from the previous request.
Here is an example of a function that can be optimized:
function buildString()
{
var newElement = document.getElementById("myitem");
newElement.innerHTML = ""; // Clear out the previous
newElement.innerHTML += addHeader();
newElement.innerHTML += addBody();
}
Here is the optimized function:
function buildString()
{
var newText = addHeader() + addBody();
document.getElementById(”myitem”).innerHTML = newText;
}





