Zed Shaw - Exposing the ‘Ghetto’

Posted on January 3rd, 2008 in Open Source, Ruby, Ruby On Rails | Comments

Before I begin, I just want to wish everyone a Happy New Year! May 2008 bring happiness, peace and prosperity to all.

I’ve been keeping myself very busy lately with RSpec and Behavior-Driven Development, basically learning the ropes and how all the pieces fit together. For now, I’m totally enjoying it. But more on that in a future post.

Now, I know that everyone who read Zed Shaw’s rant towards most of the Ruby and Rails communities will have an opinion on this. But I’ll give my own thoughts on it. All I hope is that someone doesn’t read this and think “Who the hell is this guy to give an opinion?” I might not be a ’somebody’ in the Ruby or Rails communities at the moment, but I would really like to be part of those communities sometimes in the near future.

Upon first glance, Zed’s rant seems like a completely immature piece, just looking to damage the reputations of certainl people and companies. But if you read closely, ignoring the unprofessional language scattered throughout the text, there’s a whole lot of valid thoughts and reasoning to this entire rant.

Most of his attacks are aimed at two people: Kevin Clark and Dave Thomas. Kevin Clark has been a pretty big part of the Rails community, regularly contributing code and such, and Dave Thomas of course is the author of possibly the most well-known Ruby and Rails books in the market. His story on Kevin is that they possibly never got along and clashed multiple times, while the story on Dave is that supposedly Zed had a fix for a pretty serious bug in Ruby, yet Dave and others ‘threatened’ Zed to not release it. For what reason, it’s not clear in the rant. Now, about these allegations, I don’t know whether they’re true or not (there’s always two sides to a story). But from my own views, I think any environment has these types of problems all the time. My own workplace can be used as personal experience on these manners. There’s always someone who wants to be smarter and better than you, and for some unknown reason they go out of their way to make sure they come out looking better than you can. It’s stupid, but it’s just human nature, I guess. I bet almost any other open-source community is the same.

He also goes on to write about Thoughtworks, a software consulting company that jumped on the Rails bandwagon a while back. Zed’s beef with them is the fact that they charge a shitload of cash while providing not-so-great work in return. Isn’t this is the case with almost all software consultancy places? I can name a few off the top of my head here in Puerto Rico. In fact, all you need to do is go to a website one of these ‘expert software consultants’ made, look at how the site is built, and anyone with an eye for software development standard practices can name a dozen things they would change immediately. This is no surprise here.

I do commend Zed for not making this a 100% negative jab towards Ruby and Rails. He included some people who he knows and have helped him out or were unlike those who he vilified before. Like I said, all communities have their share of bad apples, mostly people who want to be most widely known at your own expense. So the fact that he names some people who were cool to him shows that.

I’ve read a lot of other blogs where people are dismissing Zed for the way he expressed his views, that he burned his bridges and what not. But that’s what he apparently wanted. He said he’s not happy being part of the Rails community, so he wants out. This is his way of getting out. Now, I may not agree with the way he did this at all. You never know when you need to cross a bridge you burned in the past, after all. But being in the position he was, seeing and knowing a lot of things that went down, he has a valid opinion, and he’s simply entitled to it.

I think Zed partly wrote this rant not to bash everyone associated to Ruby or Rails, but to try and help out, in his own way. He knows a lot more about the community than most of us will probably ever know. So hopefully some good comes out of him exposing some dirty details on how the Ruby and Rails world is run. In the end, it simply boils down to this: It’s one man’s opinion. No matter how important he is (or rather, was) to the Rails world, one man isn’t enough to kill it, in my opinion.

Zed, if you miraculously read this, best of luck to you in the future, buddy. Hope the rant was worth it!

At the speed of Rails

Posted on December 20th, 2007 in Open Source, Programming, Ruby, Ruby On Rails | Comments

I was going to write a small post about Rails and its brand-spankin’ new release, known at version 2.0. But in the time it took to write this, the Rails community not only released Rails 2.0, but also Rails 2.0.1 (thanks to a small error in the original 2.0 release) and 2.0.2 (bug fixes and some nice changes included) were released in short order. That’s part of what I love about the entire Ruby and Rails community: You need to be on your toes and always up-to-date. It may be a pain at times, especially when there’s barely any time for one to do anything at all. But it’s just a blast, and I’m enjoying the ride.

I’ve been using the new Rails features for the past five months now, thanks to access to the Rails Edge code. I really like the direction the framework is taking. RESTful routing is now the norm, multiple views of the same chunk of data are now a breeze, huge security benefits straight out of the box… There’s just too many good things Rails 2.0 has brought out. And the upcoming release of Ruby 1.9 (and its promised speedups) have me anxiously awaiting its arrival. In fact, I’m thinking of porting my Puerto Rican Rails site, RailsPR.com, from the “obsolete” Rails 1.2.3 to benefit from all the changes made by DHH and the rest of the Rails core team. Excellent job, guys. Here’s looking towards the bright, bright future of Ruby and Rails. I’m excited to be part of it.

Source Code Management - Not just for teams

Posted on November 12th, 2007 in Open Source, Programming, Software | Comments

I’ve been meaning to write about the subject of Source Code Management for a while now. The reason for this is that I’m very surprised about the amount of software developers I personally know who don’t use any type of Source Code Management tool at all. The main reason of this is because these people don’t even know such a tool exists. The very few who do know about these tools just know how it works, but never use it themselves. It’s shocking, to say the least.

When I got this VPS, I immediately installed Subversion for my own personal projects, even though I’m the only one working on said projects. This is where those very few people I mentioned above think wrongly about these tools. Their basic response was “If you’re the only one working on the code, why do need to share it?” Very big misconception, to say the least.

The reason I originally started learning about Source Code Management tools (first started with CVS, then move to Subversion, where I have stayed ever since) because there was an additional programmer in my company who was beginning to modify the software where only I had previously worked on before. So yes, I used SCM tools to ’share’ code and make sure our changed didn’t conflict with each other. But then I realized that I was only using probably less than 5% of its true power.

When I did a major screw-up and pushed some bad code into the repository and then into production by mistake (it was actually incomplete code I had mistakenly committed to the repository), I was grateful that I could roll back almost immediately. Then when I needed to have a separate copy of the code, I learned the wonders of branches and tags.

After these experiences, I wondered how I ever did any serious programming work without any Source Code Management. Right now, whenever I start a new project, I immediately create the basic folder structure for the SCM before doing anything else. I think it’s crazy to go forward with a new project without any SCM in place, which makes the fact that a lot of programmers aren’t using any SCM just insane.

For those of you not using any SCM right now, shame on you! Allow me to redirect you to a couple of interesting articles for my preferred SCM tool of choice, Subversion. Please note, there are a lot of different SCM options out there, both commercial and open-source. I would recommend doing some research first on these different tools before deciding to go with one.

Subversion Book - Version Control With Subversion - Excellent resource not only for finding out how Subversion works, but how SCM tools work in general.
Software Branching And Parallel Universes - Great blog post from Coding Horror that explains how branching works visually, along with some reasons when not to use branching.

http://www.codinghorror.com/blog/archives/000968.html

I want everything!

Posted on October 12th, 2007 in Open Source, Programming, Ruby, Ruby On Rails, Software, Web Development | Comments

The past two weeks I’ve been totally separated from all of my learning and reading processes I’ve established to myself, and I felt terrible for doing that. It’s not like I’ve been totally disconnected from everything. I’ve still read all my favorite programming-related blogs, as usual. Still, I haven’t just sat down to absorb everything or practice.

These past two days I decided to get back on track. However, I found myself with the same problem I’ve had for a while now. Whenever I sit down to learn something, I want to learn everything. I don’t mean “learn everything of something“. It’s more like “learn something from everything“.

For the past months, I’ve had a hundred different interests. I’m interested in learning Adobe AIR. Microsoft Silverlight sounds like something I could use in the future. I was sold on Test-Driven Development and ever started to adopt its practices to my daily usage, yet recently I’m liking the sound of Behavior-Driven Development more and more and would like to test that road. I want to learn other web frameworks in different programming languages, like Django and CakePHP. And of course, I’m still totally into Ruby and Rails.

I know a lot of people who don’t mind knowing about everything. But the deal is that by learning (or having the desire to learn) about so many things, you don’t fully learn it all. You only learn a bit about each thing, but never a whole lot. There simply isn’t enough time in the world to do so, especially with a full-time schedule. So to say it’s frustrating is an understatement to me.

One technique I’m finding useful to juggle these interests is to create a necessary project in your mind to learn along the way. This should keep your interests level high during the learning process, while making you stay focused with one or two things at a time. For example, my next project is a web application, where I’ll strictly try to use the practices of Behavior-Driven Development while learning to use RSpec. This way, I’ll be learning a lot of different, yet related, subjects at the same time. After this project is done, I’ll see where Adobe AIR has headed, since it’s still in Beta. If it still piques my interest, I’ll create a new project for one of my current needs, and learn from there.

Being in this world of programming and technology, where it seems like time is always on fast-forward, it can be tough to keep up with what you like. But at the same time, it’s just fun. Even though I get frustrated at times, I’m having a ball learning these things. I guess it all boils down to that for now.

RailsPR.com - A Ruby and Rails community for Puerto Rico

Posted on October 1st, 2007 in Open Source, Ruby, Ruby On Rails | Comments

Note: Unfortunately, I had to take this site offline, due to its inactivity, and due to the fact that I have moved to New York City. I had plans for this site to be a starting point for me to start my own Ruby and Rails User Group in Puerto Rico, but I obviously can’t do that now. Hopefully someone in the near future in Puerto Rico will want to do something similar.

Although I finished this project a while back, I hadn’t announced it anywhere, so here it is. I just finished RailsPR.com, a site which I hope generates some much needed attention to the Ruby programming language and Rails framework here in my native land of Puerto Rico.

The main reason I started this site is because the IT industry in Puerto Rico is currently just centered on Microsoft products. I’ve said in a previous post that I really don’t mind Microsoft, and I think some of their products are great. However, with so many stable and useful open-source alternatives in the market, from operating systems to programming languages, I don’t see why it should be this way.

I’ve been learning and using Ruby for most of this current year, along with Rails. And it still baffled me whenever I talk to other programmers, they don’t even know what Ruby is. They’re still stuck with the same Visual Basic teachings they had in college. There are even some still using COBOL.

So my mission with this site is to create a community where interested programmers from Puerto Rico can be together in one place, sharing their knowledge and experiences, which is really what open-source is all about. It would make me proud to have my site be one of the main reasons people got into Rails.

Some people just don’t care about IT

Posted on September 22nd, 2007 in IT | Comments

This was a doozy of a week at my job. Well, given the low morale spread throughout the entire company, from the office to the manufacturing employees, it always seems to be bad enough. However, things got worse yesterday. While most, (I won’t deny, myself included) were just waiting for the day to end to collect our paychecks and head home for a nice weekend. But that didn’t happen.

In the afternoon, one of the newly-bestowed ’supervisors’ (and I use that term very loosely, as I don’t think he’s the right person for the job) gave one of the two IT technicians the pink slip. I don’t know the reasons for termination, and I really don’t care as it’s none of my business, but it seems to have come out of the blue, without any single or even accumulative problems to back up the termination. With this, the other IT technician, already angry for other injustices he’s witnessed personally from a management level, saw that as the straw that broke the camel’s back, and immediately handed in his resignation. Two IT technicians on Friday morning, no one left afterwards.

As I said, I don’t want to go into details into what happened. I’m a believer that things happen for a reason, and I’m sure both IT technicians, who were two of only four people I trust in that entire company, will get back on their feet, better than ever sooner rather than later. But 24 hours after the events took place, I’m still having a sinking feeling in my stomach about the way management has worked with this.

First off, while the main focus of the company I work for isn’t directly associated with computers and electronics (we’re mainly an electronics recycling company), it does play a major role in the company’s growth. The company has a subsidiary to tell used computers and electronics as part of their recycling plan. As such, you’d expect that their IT department should be one of the highest-priority and highly-coveted departments they have.

If you read the beginning and noticed the amount of employees I mentioned above, you know that this isn’t the case. As of Friday, the IT department consisted of the two technicians (the one who was fired was a part-timer, but not by choice), one guy who’s being trained as we speak to do part of the technicians duties - testing computers, installing software, etc. - and one intern used to do the tedious testing of smaller parts like memory modules and hard drives. So in one fell swoop, half of the technicians - the actual trained ones - are gone.

While I’m mostly their lone programmer, I’m the only one around who knows how to work with the servers, a mix of Windows 2003 and Linux. Add in two supervisors thrown into the mix and are not fit for the job - one is actually the marketing director, the other more geared in working with industrial equipment rather than computers - and you’ll find one very disorganized IT department. So much for being a highly-coveted department, don’t you think?

From what I’ve read around the Internet, it seems like managers of all sorts of companies realize the importance IT plays in their overall strategy, but they fail to treat them as an important piece of the puzzle. And I’m witnessing this first hand. While the electronics recycling section is the bread and butter of my company, the sales of electronic equipment is what will take them to the next level. But things aren’t being done to remedy the problems at hand.

Before both technicians left, there was basically one-and-a-half technicians doing the brunt of the work - not enough for the volume they want to move. With these people gone, I just know I’m going to be called to fill in while some other hapless soul walks into this mess of an IT department. The low volume, in turn, made management angry, using scare tactics such as saying that they’re losing about $10,000 a month (which I think is bullshit - no one will withstand losing more than $100,000 a year in a company that probably doesn’t make more that $1 million, probably, for two straight years) and stating that they’re going to close the entire equipment testing operation, leaving them out of jobs. And they wonder why morale is so damn low.

While this is more of a personal piece geared at those who we lost at the company, the entire point is that if you have such great resources at your disposal, willing to get the company to reach new heights, as I personally know both technicians did, then treat them as such - an integral part of the business plan. You never know when your entire IT department just up and leaves.

Will this fail? Who cares!

Posted on September 14th, 2007 in Programming | Comments

I’ve been noticing a trend about programming news on social bookmarking sites like Digg and DZone lately. There are a lot of posts floating around indicating the so-called “warning signs” of imminent software project failure. There are even posts with titles like “How to guarantee your project will fail!” How exciting. Just makes you want to click the link and get increasingly depressed as you read the exact same reasons you’re experiencing in your own projects.

While I do think these posts offer some advice on new programmers or those still in college, I think these posts are just over-kill. There are so many posts saying the same thing, it’s extremely rare and surprising to see some new reason that has a valid point. Also, most of the points in those posts are obvious to anyone who’s been programming even for a short while. Some of those points that have been repeated ad-nauseum and obvious deal-breakers:

  • Setting unrealistic goals (Really? If I set an impossible goal, does that mean I’ll most likely fail?)
  • Adding more people to a delayed project (A manager who thinks that new employees will automatically hit the ground running is one who should be shot - or at least not in a managerial position.)
  • No source code system (Any IT department without any type of backup is just asking for trouble. Hell, any individual programmer working solo on a project should be smart enough to use source control and other ways of backing up your code.)
  • Unmanaged schedule or, worse yet, no schedule at all (Again, really? But winging it is so much fun!)

All of these posts basically state the same reasons over and over again. I’d be glad to send these posts over to someone who’s learning programming now, or a manager (like mine, unfortunately) who doesn’t have the slightest clue on how to manage even the simplest of software projects. But the point is that these articles are written and posted in places where the audience consist largely of professional programmers with many years of experience under their belt. So what’s the point? I’m sure they know more than this, and have experienced at least two or three axed projects because of these same things.

If you really want to help, just point your readers to go grab a copy of books like The Mythical Man-Month or Dreaming In Code. These stories of real software failure provide more than enough information on avoiding software disasters. They’ll offer much more insight to problems in software development than any one post has. In short, those who forget history are condemned to repeat it.

So, seriously, please stop writing these posts. You’ll be better off working on not making your project fail or something.

Capistrano - Like that person you hate, yet end up falling in love with

Posted on September 3rd, 2007 in Open Source, Ruby On Rails, Software | Comments

One of the reasons I went exploring into Rails was because of Capistrano, a utility that greatly helps deploying Rails sites into production servers, by automating many of the tedious setup steps needed to deploy new changes into production. I know I can’t be the only one who has once or twice pushed some new change into production, only to discover (by myself or an angry user) that I forgot to bring the database schema up-to-date as well. Capistrano (actually, migrations are the key component here) will never allow that to happen again.

In a nutshell, Capistrano does the following:

  • Logs into your server via SSH
  • It creates a directory structure that’s useful in case you want to rollback some bad code you mistakenly pushed unto the server
  • Uses Subversion (or other SCM) to checkout the latest code committed into the repository and downloads it
  • Automatically runs all migrations to make sure the database is up-to-date
  • Runs other scripts, like making sure your FastCGI processes are restarted and running correctly, or restarting your web server

After nearly finishing my first public Rails site (coming soon, I promise!), I wanted to learn how to use this tool by deploying the first version into my VPN space using Capistrano. I thought this would be a daunting task, and at the beginning it was thanks to some minor errors, but after that, it was total bliss. After a few hours of tweaking my settings, I finally got it to work, and all deployments from here on out should be as simple as writing cap deploy without and remorse.

I’m going to write how I set up my deployment environment, so if anyone has had similar problems to mine, they can hopefully get past them.

First off, let me write about my app and server environment:

  • Operating System: CentOS 4.5
  • Webserver: Lighttpd 1.4.15
  • Rails Version: 1.2.3
  • Mongrel: 1.0.1
  • Capistrano: 2.0.0

After installing Capistrano on my development computer (simply using gem install capistrano --include-dependencies), I was ready to “capify” my application. To create the files used for deployment, just issue capify . at the root directory of the Rails application. This creates two files: Capify, which points to the second file, config/deploy.rb, which is the actual deployment configuration file.

The configuration is pretty straight-forward. There are some default settings that can e easily changed to reflect your production server setup. I did just that, and that’s where the ‘gotchas’ started pouring in.

After I changed the default values to my own, I wanted to set up the directory structure in my production server. To do that, simply run cap deploy:setup in the root directory of your application. That should prompt you for your SSH password to create all the directories needed in the directory specified in the deployment file (using the :deploy_to variable). However, when I did that, I got a nice error message: no such file to load — openssl.

After searching a few minutes in Google, I found my problem: I had compiled Ruby from source without the openssl-devel libraries installed in my system. Without the header files, Ruby compiled without OpenSSL support. So after installing the OpenSSL header files and recompiling Ruby (don’t forget to run make clean before recompiling), I was faced with another error message: It stated that my server didn’t exist. Then I remembered I’m running SSH in a non-standard port. Capistrano assumes it’s running on the default port, which is 22. After a few more minutes of searching, I found an option that needed to be added to the deployment file: ssh_options[:port] = xx, where xx is your SSH port number. After these changes, I was golden, as Capistrano asked for my SSH password.

After entering it in and seeing some progress in the directory creation process, I was faced with yet another error message, about a user not existing. I was assuming Capistrano was using the user name from my development box to log into the production server. In any case, this was fixed by adding another option in the deployment file: set :user, "production_user", where production_user is the user name with the appropriate permissions to create the directories and files in the production server. I ran cap deploy:setup once more, and all my directories were created. Success! Little did I know that would be only the first steps, and more troubles were looming ahead.

Once I verified the directory structure was created correctly on my production server, I went ahead and ran cap deploy:cold, which deploys my latest working version to the server, runs all migrations, updates all symlinks to the current code, and runs all remaining processes, like respawning all FastCGI processes, for the very first time. I once again ran into a small snag, as I was having permission problems running some scripts on the production server. After some more minutes of searching, I found that there’s a variable that needs to be set to make sure Capistrano runs the scripts as a specific user with adequate permissions. After adding set :runner, "production_user" (once again, where production_user is the user with the correct permissions to run your application scripts) to my deployment file, I was able to pass the permission parts, but then I hit yet another snag: I was missing a file - script/spin.

I found it odd that Capistrano was looking for this file, as it’s not automatically generated either by Rails or Capistrano. But after calmly reading the Capistrano installation instructions (instead of skimming over most of it), I saw that this file is used to recreate (or create) the FastCGI processes in your production server, to ensure that the users will get served the latest version of your app. There are many different ways to set up your FastCGI processes, depending on what the web server you’ll use. Since I use Lighttpd, I’ll be writing about that here. But you can find tons of useful information on the Internet if you use Apache, nginx or any other web server.

To remedy this problem, all I needed to do was to create the script/spin file (with executable permissions - chmod 0755 script/spin) with the following line (where /root_of_app/ is the path you described in the set :deploy_to: variable in the deployment file):

/root_of_app/current/script/process/spawner -a 127.0.0.1 -i 3 -r 5

This script calls another script called spawner (included in current versions of Rails), which verifies if there are FastCGI processes currently running. If the processes exist, they’re recreated to show the new version of the app. If the processes don’t exist, they’re created. The -a switch indicates the IP address used to direct the FastCGI processes. If you don’t use this switch, it will default to 0.0.0.0, which was causing me problems later on. The -i switch tells the script to create three FastCGI processes in sequential ports. Finally, the -r switch tells the script to verify if these scripts are still active every five seconds. This makes sure that all processes are running smoothly. One switch I didn’t use was the -p switch. By default, the spawner script creates all FastCGI processes starting with port 8000. Using the -p switch, you can specify which is the first port. In my case, the three FastCGI processes are creates using ports 8000, 8001 and 8002. You can change that default if you wish.

After you create the spin script, you’ll need to commit it to your SCM so Capistrano can find it in the production server. Once committed, I re-ran the cap deploy:cold command, and I was greeted with success at the end. My latest version of the application code was sent to the server, all migrations ran, and the spin script created three FastCGI processes on my server. Awesome! My work here with Capistrano was done. After hating Capistrano for a good while, I fixed all the kinks and can now never live without it. I love you, Capistrano.

Feeling good for myself, I immediately fired up my browser and entered my site’s URL. Too bad only 500 - Internal Server Error appeared when I went to the site. Curious, I entered the URL once again, appending :8000 at the end of the URL, and lo-and-behold, the site appeared in all its glory. So the FastCGI processes created with Mongrel were working well. But my web server wasn’t transferring the requests to one of the three processes.

After looking around for more information, I saw how FastCGI processes, Mongrel and Lighttpd work together. In a nutshell, the request for the site is sent to Lighttpd, the web server. Lighty then needs to process this request and send it over to one of the FastCGI processes, which then displays the site on the user’s screen. Lighttpd is simply used in this case as a proxy, and lucky for me, it already has some basic proxy functionality built-in. However, it needs to send the the request somewhere. I saw some tutorials online that set this up, but it seemed to always send the request to only one of the three processes, which wasn’t efficient at all.

Here is where Pound comes into play. Pound is reverse-proxy and load balancer for web servers. Basically, it takes all requests from the web servers and passes it along to the processes running the site, making sure that all processes aren’t over-worked by load-balancing all requests. After installing Pound on my production server, I had to create a configuration file, by default stored in /usr/local/etc/pound.cfg (your location may vary, depending if you compiled and installed the program from source, or just installed a package):


ListenHTTP
Address 127.0.0.1
Port 7999
Service
HeadRequire "Host: .*site.com.*"
BackEnd
Address 127.0.0.1
Port 8000
End
BackEnd
Address 127.0.0.1
Port 8001
End
BackEnd
Address 127.0.0.1
Port 8002
End
End
End

This configuration will make Pound listen to the requests on port 7999 in the local machine (my production server), and forward the site’s requests to one of the three FastCGI processes created by the spawner script I talked about previously. I was surprised at how something so powerful could be easily implemented.

Now all I needed to do was to configure my web server to direct all site requests to Pound, which in turn passed them along to one of the three FastCGI processes. Skipping all the other default settings and changing all sensitive info that may compromise my site, here are my current Lighttpd settings for the site in question:


$HTTP["host"] =~ “(^|.)site.com$” {
server.document-root = “/home/production_user/railsapps/app_name/current/public”
server.error-handler-404 = “/dispatch.fcgi”
server.errorlog = “/var/log/lighttpd/site.error”
accesslog.filename = “/var/log/lighttpd/site.access”
proxy.server = ( “” => ( “site” => ( “host” => “127.0.0.1″ , “port” => 7999, “check-local” => “disable” )))
)

Make sure you load the mod_proxy server module so you can use the proxy.server option mentioned above.

Once I restarted Lighttpd, I entered my site’s URL, crossed my fingers, and… success! I finally had a working site, load-balanced and all. What set out to be a learning process in Capistrano in turn made me use load balancing techniques in my site, which was something I planned on doing, but on another day, thinking it was super-complicated.

From here on out, every time I make a change I want to push to my site, all I need to do is run cap deploy on my development box, and that’s it. Everything will be updated with a simple command. It’s truly worth the time I spent getting it to work. Now I will never have an angry user again because I forgot to update the database schema.

In all, I spent a few hours fixing all the small kinks I encountered along the way. But as all good things go, you need to bust your ass to get things working like you want to. I don’t mind at all, as I learned a whole lot in one day. I hope someone finds some solutions in this writeup.

In case you’re curious, here’s my deployment file, with all the sensitive info changed for obvious reasons:


# Application Name - Anything you want to describe your application
set :application, "app_name"
# The URL of your source code repository, pointing to the latest version
set :repository, "http://svn_repo/trunk"
# Set the user name to connect to the server via SSH
set :user, "production_user"
# Set the user name of the user with permissions to run the application scripts
set :runner, "production_user"
# Set the path where you want your application to be stored
set :deploy_to, "/home/production_user/railsapps/#{application}"
# Option to change the SSH port
ssh_options[:port] = xx
# The URL or IP Address where your application will be stored - Multiple sites can be specified
role :app, “xx.xx.xx.xx”
# The URL or IP Address where your application will be served - Multiple sites can be specified
role :web, “xx.xx.xx.xx”
# The URL or IP Address where your database lives - Multiple sites can be specified
role :db, “xx.xx.xx.xx”, :primary => true
# Task to restart the web server
task :restart_web_server, :roles => :web do
sudo “/etc/init.d/lighttpd restart”
end
# Restart the web server once the deployment is finished
after “deploy:start”, :restart_web_server

Don’t let Unicode support be the death of you

Posted on August 19th, 2007 in Linux, Programming, Web Development | Comments

You Americans (and British, Australians and any other English speakers) have it easy. When you need to create a web application, all you need to use for your text is the basic English alphabet, only 26 different characters and 10 digits. The rest of the world, myself included, aren’t so lucky. Our languages are damn complicated, with additional letters, along with such grammatical ‘features’ such as accents to see where the pronunciation is at its strongest.

Seeing that I was born in Chicago, my first language is English. Although my parents are both from Puerto Rico, they never enforced the usage of Spanish upon me. When I moved to Puerto Rico when I was 8 years old, the only word in Spanish I knew was “Gracias”. Unfortunately, I didn’t have Dora The Explorer to help me learn the language when I was a boy. It’s taken years, but I finally consider myself fully bilingual in both English and Spanish, and am usually very careful as far as spelling and grammar go.

However, I’ve been wracking my brain for a long time now when making web applications in Spanish. Sometimes the additional characters, like the letter “ñ“, or words like “presentación” are a pain to get working immediately. It’s like I have to jump through hoops to get those characters working right.

In case anyone else shares my pain (or in case I forget in the next couple of months), I’ve compiled a short list with the things you should first look for when these Unicode characters are appearing incorrectly.

Don’t forget the <meta> tag

One common mistake web developers make is forgetting to set the default character set of the page they’re working on. Without this tag, the browser will automatically set the character set to the browser’s default, usually ISO-8859-1, which does not show Unicode characters. To set the character set of the page to UTF-8, which correctly displays Unicode characters, you simply need to add the following meta tag as the first line in the <head> section:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

This should enforce your browser to use UTF-8 when displaying the page’s characters. Remember to set this first, before any other tags in the head section, or else it won’t work at all.

Check your web server configuration

I remember once working with a PHP application, and pulling my hair out because the characters simply wouldn’t display correctly, no matter what I did. After hours of searching through Google, I found out my problem. The Apache Web Server, which was responsible for serving the website, had its default character set set to ISO-8859-1. If you control your own server and can change Apache’s configuration, just go to the configuration file named httpd.conf (this name can vary, depending on your Linux distribution) and make sure the AddDefaultCharset option is correctly set:

AddDefaultCharset UTF-8

After reloading the Apache Web Server, your pages should be displaying Unicode characters correctly. With the Lighttpd Web Server, which I’m using now, I haven’t had to set any option for correct Unicode support. However, in case someone needs it, just go to your Lighttpd configuration file, go to the mimetype.assign section, search for the .html assignment, and add the following at the end:

".html" => "text/html; charset=utf-8"

Another file to verify, although not necessary in most cases, is the PHP configuration file, named php.ini. PHP is responsible enough to use the encoding set in the page by the meta tag mentioned above, but sometimes some joker decides to change the default character set in the configuration file. In this case, simply comment out the default_charset option, and reload your web server.

The database has data too, you know…

With those two fixes above, your static text should be displaying correctly. However, you notice all Unicode characters stored and retrieved from the database are still being incorrectly displayed. This is due to your database character set not being set to UTF-8. In my app, I’m using MySQL, and the database server’s default character set is set to latin1_general_cl, which apparently doesn’t display Unicode at all. If you don’t explicitly indicate which character set you want to use for your database, the default will be used for not only the database, but the rest of the tables (unless explicitly defined, as well). What we want is the utf8_bin character set, which will display the Unicode correctly.

There are different ways to change this default behavior, from starting the database server with an option to change the default character set, to recompiling the entire program (providing it’s Open Source). But I find it much easier to just remember to make your database use the correct character set. In the MySQL prompt on the command line, it’s as simple as this:

CREATE DATABASE database_name CHARACTER SET utf8;

If you have an existing database not using the UTF-8 character set, the easiest way is to use a program like PHPMyAdmin for MySQL, or your preferred GUI for your database server, and change it there. You can also do it through the command line, but I won’t go into those details here. Search Google and you’ll get a ton of information.

Your text editor has a hand in this too

Don’t forget the tool you’re using to create your web pages. They could be the ones giving you major headaches. In my case, I’m testing out Intype, which is still in alpha, but very usable. Intype has the nasty habit (which I wish is fixed soon) to automatically set the file’s character set to ANSI by default. Once you save the file with this character set, it stays that way, wreaking havoc on what you want to see.

To fix this problem, just make sure your text editor, whether it’s Intype, e, Textmate, Vim or any other text editor in vogue right now, is saving your file using the adequate character set. In my case, I’m using UTF-8 Plain with Intype, and my characters are showing up correctly.

These tips should save you a ton of headaches down the road if you’re doing web development for a non-English audience. If you have any to add, feel free to do so.

OpenID - The login of the future?

Posted on August 18th, 2007 in Open Source, Programming | Comments

Following my small rant yesterday about not logging enough programming time, I cleared my schedule completely this afternoon and evening (with a rest or two to catch the awesome G4 show Code Monkeys) to catch up with some things. It also didn’t hurt that Hurricane Dean passed rather close to Puerto Rico, meaning that my plans were all washed out, but that’s okay, I don’t blame freak forces of nature for any of that.

The first thing I did was read some news around the ‘Net, as I usually do, and I saw a rather interesting article about OpenID, which piqued my curiosity. In case you don’t know, OpenID is (according to the main site) “an open, decentralized, free framework for user-centric digital identity”. In nicer terms, it’s basically a place where anyone can validate their identities in websites around the universe, by storing your allowed sites in a single place. This means you can be able to login any OpenID-enabled site by simply entering your own OpenID URL, logging into your OpenID account, allow the site, and that’s it. No more remembering multiple passwords ever again, only your OpenID URL and password.

At first, I thought this was simply a glorified password-saving system, or something similar to the ill-fated Microsoft Passport / Live system. I didn’t think it was going to be a great idea. But after reading more about it, I realized the true strength of this system over proprietary systems like Microsoft’s: It’s available for everyone who wants to use it. And I don’t mean that in the sense of creating accounts. I mean it in the sense that any developer can add OpenID functionality to their own web applications for free. That’s the beauty of the system.

Although very few sites I frequestly visit don’t have this functionality yet, I went ahead and created my own OpenID account over at MyOpenID. They’re one of the first OpenID providers, and they make the process rather easy. You simply go to their website, go through their short sign-up process, and once you have the account ready, you can go to any OpenID-enabled site (they also include a directory with sites that have this functionality enabled), and you’re ready to log into that site with the URL you created. It’s a simple, yet powerful tool.

The site I’m creating right now has a forum powered by the awesomely simple Beast forum app, and it has OpenID support right out of the box, thanks to the ruby-openid gem that you can easily install on your server. After installing the forum I’m going to test on my server, I immediately used my OpenID to create the account, and it just worked without a hitch. I’m sure everyone loves it when things work on the first try as intended.

If you haven’t read about OpenID, I suggest you click that link above to go to OpenID’s website, and read all you can about it. I believe this will cause an impact in the Open Source industry, and more applications will start to have this included. I know that whenever I can, I’ll be adding this functionality to my websites. I already found a tutorial that helps integrate OpenID functionality with the acts_as_authenticated plugin. I’ll be sure to look into that, and post my results of that experiment soon.