Installing ImageMagick from Source on Ubuntu

I like Ubuntu Server. I really like apt-get, because I don’t have to do any work at all to install stuff. It’s a piece of cake.

Unfortunately, sometimes installing using apt-get doesn’t work, or maybe the software I need isn’t the latest and greatest version on the Ubuntu repository. In such cases, there’s only one option left: installing from source.

That means downloading, extracting, configuring, building, debugging, etc. Most people shy away from doing this because it isn’t fast and easy, and stuff can break.

I recently had the opportunity to install the latest version of ImageMagick on an Ubuntu server, and it was a lot easier than I thought it would be!

Here’s how you do it…

(more…)

Avoid the Number 1 CSS Mistake: a, a:visited

I used to hate CSS. I mean, I really, really hated working with CSS at all. Then, one day, I was forced to actually learn it well to design a new web site. It was rough, but I survived.

Don’t ask me why learning CSS was so painful for me, because I can program in a bazillion different languages. For whatever reason, it was just painful. I emerged victorious, however, with the help of a lot of examples I found by searching online.

There was one little problem: the vast majority of examples I found included a little bit of code that will royally screw up all your hyperlinks. So, this post is about how to avoid the #1 CSS mistake: a, a:visited.

(more…)

Fixing the “ActionMailer: Hostname not match server certificate” Error

If you have a Rails app that sends e-mails, you are probably using ActionMailer. Unfortunately, starting with Rails 2.2.2, you may have encountered a wonderfully annoying little error that looks like this:

OpenSSL::SSL::SSLError (hostname was not match with the server certificate):
   /usr/lib/ruby/1.8/openssl/ssl.rb:123:in `post_connection_check'
   /usr/lib/ruby/1.8/net/smtp.rb:582:in `tlsconnect'
   /usr/lib/ruby/1.8/net/smtp.rb:562:in `do_start'
   /usr/lib/ruby/1.8/net/smtp.rb:525:in `start'
   [...]

The are quite a few sites out there that give monkey patches for this problem, but those aren’t very useful because the next time you upgrade Rails, the monkey patch gets obliterated and you’re back to square 1. And then you have to remember how you monkeyed with it the last time to get it working again. Ug…

Instead, fix it the right way!

(more…)

jQuery AJAX Form Submit for Dummies

AJAX Form using jQuerySo you’ve decided to be supercool and use jQuery. That was a wise decision you made, because jQuery totally rocks. Especially in Rails apps, jQuery makes life a LOT simpler. Yes, you have to learn some JavaScript and some quasi-new syntax, but it’s still seriously powerful and convenient.

There’s only one problem: if you’re like me (i.e. JavaScript-impaired), you just couldn’t get your forms to submit via an AJAX call.

You’ve probably heard of something called the jQuery Form Plugin. It’s a bit overwhelming looking at all the options and trying to extract just the functionality you need if you aren’t a JS Jedi, though. And so, without further ado, I present to you jQuery Form Submission for Dummies!

(more…)

Increase the Performance of Fragment Caching in Rails

Rails Caching OptimizationIf you use Rails on a high-traffic site, you know that as your number of users increases, you have three main options:

  1. Add servers to handle the load
  2. Optimize your queries
  3. Improve your caching scheme

You may be surprised to know that most people go for Door #1. It’s a lot easier. You don’t have to really do tons of work to rewrite your code and actually make it efficient. You don’t have to ditch “the Rails Way” and start actually thinking about what the database layer is doing to slow your site down to a crawl. And you don’t have to think about how Rails’ cache expiry functions actually work. Finally – and best of all – you can just pass the costs on to your customer, right??

I recently read an article that really slayed me. It was about a “niche site” that runs on Rails. They get 50 million hits a month, and they have SIX servers to handle the load, including multiple dedicated DB servers. I designed a Rails site that now gets 27 million hits a month, and it runs Rails on a single 1.86 GHz dual-core server with 3GB of RAM. By my calculations, the site could easily handle twice as many hits as it does now. Most of the time, the load is very low and the CPU and disk accesses hover at a few percent.

Of course, to achieve good performance, you can use things like Phusion Passenger. But that alone ain’t gonna cut it. You also have to optimize your queries, stop doing things The Rails Way and start thinking for yourself, and of course optimize your caching scheme.

In this episode, I’m going to tell you one very cool way to turbocharge your caching setup!

(more…)

Adding JavaScript to WordPress Posts Without a Plugin

JavaScript in WordPressIf you have installed your own WordPress blog on your server, you may want to include some JavaScript goodness from time to time.

The bad news is that WordPress likes to screw around with tags when using the WYSIWYG post editor. That makes it kind of hard to, say, embed a video in one of your posts.

The good news is that there is a very easy way to embed any kind of JavaScript in your posts without the need to install any plugins, or change any configuration settings. And it works beautifully with the WYSIWYG editor…
(more…)

The Easy Way to Copy a MySQL Database

MySQL Database CopyIf you have a web site of any kind, you probably have dealt with MySQL databases. Sometimes, you need to move your database, whether it’s to another server or back onto your existing server after performing an OS upgrade.

The advice you usually hear goes like this: Export the table structure and data using the mysql command line utility or with phpMyAdmin. Then reimport the exported data once your install/upgrade is done.

Well, that’s just a serious pain in the arse.

Lucky for you, there’s a very, very easy way to copy your DB over with a few copy commands…

(more…)

What to Do When Your Manual WordPress Update Dumps You Back to the Installation Page

WordPressEveryone loves WordPress – especially when it comes time to upgrade to the latest version of a plugin or of WordPress itself. You just click a button, and it does all the work.

Those of you who are used to doing things “The Joomla Way” can no doubt testify to the glory that is WordPress.

Sometimes, you can’t automatically update WordPress itself. In such cases, you need to manually install the newer version. Normally, you delete most of your old WordPress files (be sure to read the manual update instructions!), and then simply upload and uncompress the new version in your application’s directory. Voila! Everything just works…

Well, most of the time. Sometimes, it doesn’t. Sometimes, you are dumped back to the initial WordPress setup screen. If you fill in the fields and carry on with the install, it will look like you have just destroyed your entire old WordPress site when you are greeted with a default, empty home page.

Fortunately, you haven’t destroyed anything! Here’s how to get your site back in just 3 steps…

(more…)

SyntaxHighlighter: Prevent #{var} in a Ruby String from Being Parsed as a Comment

WordPressWordPress is a seriously popular blogging platform, primarily because it simply rocks. In fact, this here blog uses WordPress.

Since I generally write posts about programming issues, I needed a good plugin for automagically highlighting code segments. I ended up choosing SyntaxHighlighter by Viper007Bond.

While it generally kicks butt, there is one little bug that is particularly annoying for those of us who post snippets of Ruby code: including a variable in a string like 'this is a #{color} string' causes SyntaxHighlighter to make everything after the “#” into a comment, which it wraps down to the following line.

That simply won’t do…

(more…)

Calling a 32-bit System Command from a Script in x64 Windows

64-bit ScriptingLet’s say you’ve written a little 32-bit script that calls a Windows command such as nbtstat. When you try to run the script in x64 Windows, you get an annoying “File not found” error – even though you can see the command sitting in the \Windows\system32 folder.

What’s going on here?

x64 version of Windows have two system folders: \Windows\system32 and \Windows\SysWOW64.

The 32-bit commands are in the SysWOW64 folder, and the 64-bit commands are stored in the system32 directory. x64 Windows looks in system32 by default when you call a command line function, since it tries to call the 64-bit goodies (no, that’s not backwards!).

So, you might think that you can simply change your script to explicitly call, for example, \Windows\system32\nbtstat instead of just nbtstat, and you’ll be off and running, right? Wrong.

Fortunately, there is an easy way to solve this little problem…

(more…)