This is old content! The catacombs are a snapshot of content created from 2005-2007. For new stuff, visit Maniacal Rage.

maniacal rage

Garrett Murray lives here. He's the senior developer at Blue Flavor by day and an amateur writer and comedian by night. You can read more about him or
Garrett Murray's hCard
photo

This is a quick tutorial on creating graphical dates using SimpleLog. Since I released the newest design of this site, which features graphical dates, I've received a few requests from SimpleLog users for a short how-to on the subject. Here goes:

First, create the 0-9 images. Try to make them as uniform as is possible. You can always add padding space between them later using CSS, so don't pad them too much. Save them as 0.png, 1.png, et cetera. Pretty logical. Put them in your theme's images directory, maybe in a subdir called "numbers." You should also create a dot graphic and a colon graphic (or a / or a - or whatever you want to use as a separator.)

Next, tweak your theme's views to use the new graphics. You're going to modify themes/your_theme/views/posts/_item.rhtml and _item_detailed.rthml. The latter is the partial used on individual post archive pages (or permalinks). Here's a simple way to use the graphics:

<%
# We're going to store the image code as we build it
link_img = ''

# For loop iteration
i = 0

# Choose which separator to use and set the datetime string
# The following will produce MM.DD.YY
sep = 'dot'
dt = post.created_at.strftime('%m%d%y')

# Loop through each character of the datetime string
while i < dt.length
  # Add the digit, use theme_image_path to generate a theme-specific URL
  link_img << "<img class=\"dt\" src=\"#{theme_image_path('numbers/' + dt[i,1])}\"/>"

  # Add a separator if we've gone two digits
  link_img << "<img class=\"dt\" src=\"#{theme_image_path('numbers/' + sep)}\"/>" if i%2 != 0 and i != dt.length-1

  # Increment the iterator
  i+=1
end

# Now we've got our image in link_img, we can use it
-%>
<%= link_to link_img, Post.permalink(post), :title => 'Permalink for this post' %>

Now, there are plenty of ways to choose which separator or datetime string to use. This is a very simple example that uses only the month, date and year with dots separating them. You could do something more complicated like, say, YYYY-MM-DD HH:MM:SS by using code like the following:

<%
# Set the separator to hyphen first, set the full datetime string we need
sep = 'hyphen'
dt = post.created_at.stftime('%Y%m%d%H%M%S')

# Loop through
while i < dt.length
    # If we've passed the last part of the date, change the separator
    sep = 'colon' if i >= 7

    # Add the digit, use theme_image_path to generate a theme-specific URL
    link_img << "<img class=\"dt\" src=\"#{theme_image_path('numbers/' + dt[i,1])}\"/>"

    # Add a separator if we've gone two digits but don't add one between the date and time
    if i != 1 and i != 7
        link_img << "<img class=\"dt\" src=\"#{theme_image_path('numbers/' + sep)}\"/>" if i%2 != 0 and i != dt.length-1
    elsif i == 7
    # Add a space between the date and time
        link_img << '&nbsp;'
    end

    # Increment the iterator
    i+=1
end
-%>

Obviously, the second example is a little more complicated, but due to the various requirements (year is four characters without a separator, space between the date and time), it has to be. It's still quite easy to put in place, though. These might not even be the best way to do this, but it's a quick and dirty method that works.

Once you've got this code in place, you can easily customize the padding/spacing of the graphics using CSS.

Check out the SimpleLog wiki or forums for other SimpleLog tips, tricks and user feedback.


Here's how I create a new Rails app and start version control using SVN. I keep my repositories in a directory called source and I develop in a directory called rails (under the default sites folder), both in my home directory. For the purposes of this tutorial, I will be creating a new Rails project for development of this site.

This all assumes you've got Ruby, LightTPD (not required), SVN and Ruby on Rails installed. Need to install Ruby/Rails? Check out Dan Benjamin's tutorial over at Hivelogic. It's excellent. Need to install SVN? Check out Dan Benjamin's other tutorial over at Hivelogic, or you can use one of Martin Ott's pre-built packages. This also assumes you're using OS X. Most of this would apply to other platforms, but you'll have to tweak it on your own.

Of course, please be careful, et cetera, no guarantees, you know the drill with all of this. I'm just posting it here so other people can benefit from it, but I can't promise it will work for you (as always, be careful).

  1. Create an SVN repository.

    svnadmin create ~/source/maniacalrage.net
    
  2. Create a basic directory structure for the repository. I use the recommended three top level directores: branches, tags and trunk. I work out of trunk and create branches when I have stable builds. Create this structure in a temporary directory (created below) and then import it into the new repository.

    mkdir ~/temp
    mkdir ~/temp/branches
    mkdir ~/temp/tags
    mkdir ~/temp/trunk
    
  3. Do the initial import of this structure. Note that the location of the repository must be explicitly stated—you can't use ~/. Of course, all ~/ means is /users/your_user_name. Once you're done, you can trash that temporary directory you created (be careful with that rm command!).

    svn import ~/temp file:///users/garrett/source/maniacalrage.net -m "initial import"
    rm -r ~/temp
    
  4. Let's check out your local working copy. There are a couple of things to note about the checkout line—once again, you must specify the full path to your repository (and this time, include the trunk directory since that's where you'll be working from), and you need to give the checkout command the name of the folder you want your working copy to exist in. The most logical choice here is maniacalrage.net.

    cd ~/sites/rails
    svn checkout file:///users/garrett/source/maniacalrage.net/trunk maniacalrage.net
    
  5. Okay, it's time to create your Rails app. You're going to create it inside the directory you just created when checking out. Rails will simply add files to the existing directory.

    rails maniacalrage.net
    
  6. Now that we've got our Rails app in place, we need to add everything it just created to SVN. We're going to force SVN to accept all the files and directories.

    cd maniacalrage.net
    svn add . --force
    
  7. Check those files in.

    svn ci -m "initial rails import"
    svn up
    
  8. We don't want our log files versioned, so let's remove them from SVN and tell SVN to ignore them in the future. You could also ignore the database.yml file, but I never do since I always mimic my development environment's settings when I work from various machines (i.e. I use the same MySQL login and password from machine to machine).

    svn remove log/*
    svn propset svn:ignore "*.*" log/
    svn ci -m "removing log files and ignoring them in the future"
    svn up
    
  9. (If you're going to use Webrick as your local testing server, skip these last two steps—they only apply to LightTPD.) Run your Rails app for the first time and then shut it down (using control-c on the keyboard). This will create the config/lighttpd.conf file.

    ./script/server
    
  10. Add the new conf file to your repository.

    svn add config/lighttpd.conf
    svn ci -m "added lighttpd conf file"
    svn up
    

And you're done. This may seem like a lot of work, but it's actually rather trivial once you've done it once or twice. From this point on, you can begin developing your Rails app and you're all set up for version control. Where do you go from here? A few places:

  • The SVN Guided Tour.
  • SvnX is an open GUI client for Subversion and OS X. Will make several things easier on you in the long run, especially diff viewing with its bundled FileMerge integration. It's also free.

In addition to the following tutorial, you might benefit from the following points of advice:

  1. Open config/lighttpd.conf and change server.port from 3000 to 80. This will allow you to access your site from localhost rather than localhost:3000. This requires you run your local testing server a bit differently, however. First, you need to disable the built-in Apache instance running on OS X, since it runs on port 80.

    /System/Library/StartupItems/Apache/Apache stop
    

    And then you need to launch your server as such and enter your password when prompted:

    sudo ./script/server
    
  2. Add a virtual host to your hosts file to simplify development. For instance, since I'll be developing this site, I'd rather access dev.maniacalrage.net on my local box than localhost. Assuming you have TextMate installed (of course you do!) and the shell command enabled (No? Just visit "Terminal Usage..." in the Help menu in TextMate), open your hosts file for editing:

    mate /etc/hosts
    

    And then add a line after the first localhost line:

    127.0.0.1  dev.maniacalrage.net
    

    Save, enter your password when prompted, and close. Now you can view your new URL when developing and you'll get your Rails app.

Now get to work building your new Rails application, send me lots of gold, and subscribe to the podcast!