Charles on Software

Opinions about designing, programming and using software

I haven’t written a lot of C++ using Visual Studio 2008, as I usually write .NET apps using C# these days.  However, I was writing a quick little console program in C++ and needed to convert command-line arguments to doubles.  By default the Project Wizard creates the code to use Visual Studio’s _t functions, which are really macros that expand to functions that accept either ANSI or wide strings, depending on whether _UNICODE and _MBCS are defined.

As a result, when I wanted to convert a string to a double, I used _ttof, which was the version that I’d used in the past with older versions of Visual Studio.  It is resolved to either atof or _wtof by the preprocessor, depending on whether the symbols listed above are defined.

continue reading…

Peter Mirus, the CEO of Trinity Consulting, sent me email pointing out the HipHop project from Facebook.  HipHop is a program that converts PHP to C++, then compiles it using gcc.  The idea is that you can write your code in PHP but still get the speed benefits of compiled C++.  It’s an interesting idea and seems compelling at first glance.  If you have code written in PHP that is CPU-bound, why not convert it to a language that allows for much faster execution?

Anyway, HipHop is interesting academically, but I don’t buy some of the arguments they’ve listed.

You keep coding in simpler PHP …

Simpler for whom?  PHP has a veneer of simplicity that appeals to the unwary and disguises lurking complexity waiting to bite you.  A lot of other people have covered PHP’s issues, such as the “==” and “===” operators.  I find C++ to be simpler due to strong typing, explicit variable declaration, etc.  You can prevent yourself from making mistakes.

Companies with large PHP codebases will generally rewrite their complex functionality directly as PHP extensions in either C or C++. Doing so ends up reducing the number of people who are able to work on the company’s entire codebase.

continue reading…

I was thinking about application configuration and how to handle it in Rails, so I did a little Googling.  I found Railscast #85, which addresses the issue.  I was able to use the information provided by the author, Ryan Bates, to quickly whip up a configuration file containing information specific to my application.

In the process, however, I noticed that some issues were not addressed.  They are:

  1. Storing some types of data, such as passwords or private keys, in configuration files that are under version control might not be a good idea.  Mr. Bates acknowledged this around the two minute mark.
  2. It’s generally considered a good practice to store sensitive information outside the document root.  That way, if the raw code is served (instead of the rendered HTML) via a configuration error or security hole, the sensitive information won’t be exposed.

continue reading…

I went to test the URI class from the Addressable gem, looking for a replacement for the URI of the standard ruby library.  The gem installation went smoothly, but as soon as I tried to use it, I got this error:

irb(main):003:0> require 'addressable/uri'
LoadError: no such file to load -- addressable/uri
 from (irb):3:in `require'
 from (irb):3

Googling the main error (“LoadError: no such file to load”) turned up this blog post by bparanj. While it talks about Selenium, the solution applies to any gem.

Acrobat Reader informed me that an update was available and asked if I wanted to install it.  Since PDFs have become a common vector for malware, I try to keep my copy of Acrobat Reader patched.  When installing the patch, however, I got the following error:

the installation source for this product is not available

continue reading…

I installed apache and MySQL on my Windows XP laptop by using WampServer.  It’s convenient for setting up a local development environment.

I’m creating a Rails application and ran “rake db:migrate” to create the database tables for my project.  When I did so, I got the following:

rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
C:/Program Files/ruby/lib/ruby/1.8/benchmark.rb:306: [BUG] Segmentation fault
ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32]

This was a bit of a thorny problem.  Fortunately, stackoverflow.com user “blue_rubber_ducky” found the answer and posted it in this thread.  Thanks to the author “protech_v2″ who posted to the aptana forum and to blue_rubber_ducky for updating the original post on stackoverflow.

While creating a Ruby on Rails application for the first time under Windows XP, I ran into a problem.  I usually do Ruby on Rails development on Linux, but I’ve been wanting to do it on my laptop; it runs XP, since I do a lot of .NET development.

When I ran “rake db:create” to create my database, I got the error:

This application has failed to start because libmysql.dll was not found

A quick bit of googling and I found this thread at ruby-forum.com.  Copying libmysql.dll to ruby/bin took care of the problem.

I was adding 301 redirect rules to an .htaccess file for a client.  I had converted a site from static HTML to PHP, and wanted to make sure that external links were not broken.  After uploading the changes to the server and testing, I got the following error:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

After a bit of head scratching I realized that one of the file names contained a space. I hadn’t spotted it because I’d generated the redirection rules via a Ruby script, rather than typing them all in by hand:

Redirect 301 /foo bar.html http://www.example.com/foo bar.php

This space was causing apache to throw an error when parsing the file. Enclosing the URLs in quotation marks solved the problem.

Redirect 301 "/foo bar.html" "http://www.example.com/foo bar.php"

Normally I try to avoid filenames with spaces in them when creating web-sites.  This site, however, was created by someone else and I was making a very specific change to it that required converting the files to PHP.  I automated as much of it as possible, mass renaming files and using search and replace across all files.  As a result, I never realized that one of the filenames contained a space until I found the problem above.

A client had a WordPress theme that made use of timthumb.php to generate thumbnail images on the fly.  If you check the documentation for the script, it tells you to set the permissions for the cache folder to “777″.  This is short-hand for “all users are allowed to read, write, create and execute files in this directory”. This blog post from Chad Coleman provides a rather useful guide for using the script in a WordPress theme. It goes one step farther and tells you to set the permissions for both the cache folder and the script’s containing folder to “777″.

This is bad advice.  The WordPress Codex has an explanation of the dangers of 777 permissions.  Don’t do it.  It may be necessary to use them on some badly configured hosts, but if you run into that situation, get a new host with a competent administrator quickly.

Some web hosts prohibit the execution of scripts that reside in folders with 777 permissions in order to protect their users from such bad advice.  If you are using a WordPress theme that makes use of timthumb.php and are not seeing the thumbnails, I suggest that you alter the permissions of the folder containing the script and the cache folder to at least 755 (only the owner can write/create files in the folder).  Frankly, I think that 600 (owner can write and read, but not execute, no one else has any access) is a good default for anything except anonymous FTP folders.

Last month I reviewed the DJ-Promedical template for Joomla!.  A representative commented on the review and argued a couple of points that I made.  They pointed out a link to the documentation, which I have confirmed and reviewed.  As a result, I have updated the original review.

In my review, I also stated that the template was a Joomla! 1.0 template, not a Joomla! 1.5 template as advertised.  The representative replied:

This is a template for joomla 1.5 and there is no need to modify code
before using it on joomla 1.5 ! continue reading...