May 25th, 2009

Hello Comments

Search, categories, and what else? Oh yeah, comments! You can now leave your opinion, negative or otherwise, on any of my posts (that aren't over a week old). So feel free to flame, though you might get banned, but hey! The only bit missing out of the comment system is a way to preview your comment, I'll probably tackle this with a bit of AJAX trickery sometime this week or next. The previous CMS I wrote has all the code for previewing comments; however, the code is a bit dirty, and I'd like to take the time to write a fresh version (and maybe a tutorial to go along with it).

1 comment · Continue reading

May 23rd, 2009

Search is Back

My Saturday morning work quota is complete, and so is the search feature! (What I won't mention is that I had already written the code last week and just never bothered committing it until now.) Anyway, have fun finding stuff!

Update: Post categories are now viewable; however, the show pages need some prettying up. Also, just to tempt people, the comments count shows up under each post... you just can't write comments yet! (Bad joke, I know)

0 comments · Continue reading

May 14th, 2009

About Halfway Through May

I'm not sure what really happened, but the last time I wrote here was back in February. Back then I just started work on a website for a local garden center, Scent-Sational Plants, which has been launched, though it's not fully operational; archiving and photographing every single plant one owns takes some time, so that part of the site is inaccessible for now. The other project I had going at the time was a tumblelog. Everything worked fine, or would have with a little more time, but I just decided to put it on hold. One reason for doing so was the lack of a proper design, and also the pending release of Rails 2.3.

In the meantime I've kept my self... occupied. Everything seems to get more intense as the end of term nears, and being my graduation year makes it even more tiresome (but awesome!). It's only recently that I've found some time to play around in Rails again, and update my website at the same time. The new design is barely worth mentioning, even though it was the first piece I finished. The star of the show is the fresh application running everything. Doing a full re-write was never my original plan; however, it was well worth it. I went all out this time, that means a full admin panel complete with a custom design and lots of nifty widgets.

What's Missing

It may seem a little sparse right now, that's because some pieces haven't yet made it to the public side of the website. Those include categorized posts, multiple authors and a curious comment system. All of which are fully functional, and will slowly be added in due time. The only thing that makes the comments, "curious", is that it's now polymorphic. Which will allow me, one day, to extend it's scope into other parts of the site, say a photo gallery or back-end multi-author editing with criticism comments thing.

What's New

Here are a few screenshots of the admin panel. It's pretty modular, so the basic design from these pages carries into everything else.

The Dashboard

A list of recent activity around the site. It's just done by a global observer on all saves, updates and deletes.

Dashboard Screen

Post List

Lists all posts and basic information about them. The same design is used for categories and users, just different columns.

Post List

Publish Page

A post has a summary, body and extended field, which make up the content of the post. I can select multiple categories, or set the publish date in the future, or even set a custom permalink (I've kept the id-post-title format so as not to break too many links, Update: Changed to just permalink).

New Post Screen

That's all there is to it for now. Eventually I'll add some more features, such as automatic comment expiration, or post drafts/revisions. For now, it does just what I need.

0 comments · Continue reading

February 7th, 2009

Works in Progress

It's definitely been a good last few weeks for me. First signed on a project for a garden center, and made some good business connections (both local!), secondly I've almost completed my tumblelog application, which as of yet has no name. The only features missing are a few post types, videos, audio and pictures to be precise. Sure they may be the trickiest to implement, but I love challenges. It should hopefully be done by the next VicRuby meet-up (February 25th, 7:30 PM at the Fernwood Inn), so I can show it off.

Here's a few snippets I've found useful as of late:

#
# I use this to convert pixel font-sizes to ems.
#
def em(pixels)
  pixels.to_f / 16.0
end

#
# Gets those nested em line-heights/margins/font-sizes.
# If you know the documents base line-height then it's faster
# to just divide it by the parent's font-size manually.
#
def nested_em(child, parent)
  child.to_f / parent.to_f
end

This is my version of Apple's Time Machine, couple it with a cronjob and you're golden.

#!/bin/bash

rsync -avl --delete --stats --progress "/Users/mat/Documents/Important Data" "/Volumes/External HD/Backups/"
rsync -avl --delete --stats --progress "/Users/mat/Documents/Legal" "/Volumes/External HD/Backups/"
rsync -avl --delete --stats --progress "/Users/mat/Documents/Portfolio" "/Volumes/External HD/Backups/"
rsync -avl --delete --stats --progress "/Users/mat/Documents/Programming" "/Volumes/External HD/Backups/"
rsync -avl --delete --stats --progress "/Users/mat/Documents/Projects" "/Volumes/External HD/Backups/"
rsync -avl --delete --stats --progress "/Users/mat/Documents/School" "/Volumes/External HD/Backups/"
rsync -avl --delete --stats --progress "/Users/mat/Documents/Server" "/Volumes/External HD/Backups/"
rsync -avl --delete --stats --progress "/Users/mat/Documents/Writings" "/Volumes/External HD/Backups/"

That's it for now. There may be a new design in store for my website, but it won't happen till after the release of Rails 2.3.

0 comments · Continue reading

January 21st, 2009

alias_attribute

The jewel that is alias_attribute "allows you to make aliases for attributes, which includes getter, setter, and query methods". Observe how these 18 lines of code becomes 3.

def code
  content
end

def code=(code)
  self.content = code
end

def title
  header
end

def title=(title)
  self.header = title
end

def url
  cite
end

def url=(url)
  self.cite = url
end

This piece of code was taken from a tumblelog app I've been working on, it makes use of single-table-inheritance (STI) to store the posts. On different post types, for example code snippets, It would be nicer to be able to use snippet.code instead of snippet.content, or always having to remember what each attribute represents.

Time for a magic trick.

alias_attribute :code, :content
alias_attribute :title, :header
alias_attribute :url, :cite

This code does the exact same as above (getters, setters and nice names). Just in 3 lines, instead of 18.

alias_attribute(new_name, old_name)

That's a wrap. Thank you Paul Cortens for the kick in the right direction with alias_method.

0 comments · Continue reading

About Me

I live in Victoria BC and I write code... mostly Ruby. I work in a little company called Clear Object, we design and develop websites. Other than computers, I enjoy the outdoors, especially biking. Feel free to email me: mat dot harvard at gmail dot com.

About the Site

This is where I write about things that interest me, typically that means programming, and specifically that means Ruby. The site runs off a Rails application I wrote. This is also the sixth major design revision. Older posts can be found in the archives.

Featured Articles