Subscribe to the MPC blog rss feed feed-icon-14x14
 

Playing with Django

Posted on 02:09PM on 09/02/2008
Tags: django

Yesterday I had a brief opportunity to play around with Django for the first time in a while. I'm proficient in Python, and I've done work previously with Django, but it's been a while. Lately I've been enamoured with Sinatra, a Ruby web framework that's much more lightweight than Rails. Django feels odd at the moment, maybe because I've been away for a while. In my next post, I'm planning to write up a bit of a comparison between Django and Ruby frameworks. I know - it's been done to death, but I feel like writing and am looking for an outlet.

0 Comments (Show) (Comments are closed for this post)

Handling IE Differently

Posted on 01:27PM on 08/31/2008
Tags: browser, blog

I noticed when viewing this site in IE 7 that the tabs at the top of the page were not properly aligned. They look good in Firefox (on Ubuntu) and Konqueror, but not IE 7. Big suprise, right? Anyway, the easiest thing to do is create a stylesheet specifically for IE that overrides the existing styles and is only loaded when the requesting browser is IE. The conditional code can be placed in the header section of the layout file. For example:

  
   

This seems simplest. If the browser is IE, the additional stylesheet will be loaded and the styles will be properly overriden. Is there an easier way to accomplish this?

0 Comments (Show) (Comments are closed for this post)

Sluggable Posts

Posted on 06:44AM on 08/11/2008
Tags: blog, slug

I was putting it off, but I decided tonight to implement slug urls in the blog. It's still in beta mode, so I feel its ok to go ahead and make the change.

So, now instead of seeing urls like: http://mattpayne.ca/blog/post/3, the urls will look like: http://mattpayne.ca/blog/post/this-is-a-post

I think it looks much nicer and also somewhat hides the data implementation. For all anyone knows, the posts could ve stored in an xml file on the server.

0 Comments (Show) (Comments are closed for this post)

Counting Post Tags

Posted on 05:16AM on 08/11/2008
Tags: ruby, blog

I decided to adopt the simplest possible approach to recording blog entry tags. Each post has a string property called tags, which simply corresponds to a text field in the MySQL database. Each tag in the string is simply separated by a space. I'm the only one creating posts, so why bother with something more complicated? At some point I may need to breakdown and create a normalized data model for it, but for the time being I'm happy. In creating this site, I wanted to be able to create a tag cloud with each tag having a count of the number of posts it was applied to. This proved a fun challenge. Here's the code:

class Tag

  attr_reader :tag, :count

  def initialize(tag, count)
    @tag, @count = tag, count
  end

end

class Post < Base  

 #Other code ...

  def self.all_tags
    hash = self.all.inject({}) do |h, post|
      unless post.tags.blank?
        tags = post.tags.split(" ")
        tags.each {|t| h.key?(t) ? h[t] += 1 : h[t] = 1}
      end
      h
    end
    #shuffle just randomizes the array of tags
    hash.inject([]){|arr, (k,v)| arr << Tag.new(k, v); arr}.shuffle
  end

  #Other code ...

end

Overall, I'm happy with this approach. We'll see how well it scales.

0 Comments (Show) (Comments are closed for this post)

Letting Google Know About The Site

Posted on 04:56PM on 08/10/2008
Tags: google

I just went through most of the tools in Google's webmaster tools. Interesting stuff. I created at robots.txt file and placed it in the root of the site. I also created a sitemap.xml file and placed it in the site's root. According to Google, these are two of the most important pieces to have in place if you want your site indexed. Interesting stuff up there for webmasters - lots of analytical tools. Check it out.

0 Comments (Show) (Comments are closed for this post)

More

1 2 3 4 5 6 7 8
Please note that I am currently unavailable for any large, long term work.