<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US">
  <id>tag:matharvard.ca,2005:/posts</id>
  <link type="text/html" href="http://matharvard.ca/posts/" rel="alternate" />
  
  <title>Mat Harvard</title>
  <updated>2011-10-05T23:16:39-07:00</updated>
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/matharvard" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="matharvard" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
    <id>tag:matharvard.ca,2005:Post/13</id>
    <published>2011-10-05T23:16:39-07:00</published>
    <updated>2011-10-09T15:02:02-07:00</updated>
    <link type="text/html" href="http://matharvard.ca/posts/2011/oct/5/steve-jobs/" rel="alternate" />
    <title>Steve Jobs</title>
    <summary type="html" />
    <content type="html">&lt;p&gt;&amp;ldquo;Stay hungry. Stay foolish.&amp;rdquo;&lt;/p&gt;</content>
    <author>
      <name>Mat Harvard</name>
    </author>
  </entry>
  <entry>
    <id>tag:matharvard.ca,2005:Post/12</id>
    <published>2011-09-12T00:48:55-07:00</published>
    <updated>2011-09-12T01:01:49-07:00</updated>
    <link type="text/html" href="http://matharvard.ca/posts/2011/sep/12/waves-updated-to-rails-3-1-0/" rel="alternate" />
    <title>Waves updated to Rails 3.1.0</title>
    <summary type="html">&lt;p&gt;Due to unforeseen circumstances, I had to delete and re&amp;ndash;make the repository on GitHub for my MongoDB and Ruby on Rails powered tumblelog engine.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;I&amp;rsquo;m sorry to the followers the repository had. I made a mistake, which ultimately the easiest solution for me was to just clean the repository and start fresh.&lt;/p&gt;

&lt;p&gt;I spent some time today updating Waves to Rails 3.1.0. There are some deprecation warnings related to the Joint gem, but those should be fixed upon it&amp;rsquo;s next update.&lt;/p&gt;

&lt;p&gt;The repository is available at the same URL as before.

&lt;p&gt;&lt;a href="http://github.com/matharvard/Waves" target="_blank"&gt;github.com/matharvard/Waves&lt;/a&gt;&lt;/p&gt;</content>
    <author>
      <name>Mat Harvard</name>
    </author>
  </entry>
  <entry>
    <id>tag:matharvard.ca,2005:Post/11</id>
    <published>2011-08-30T21:37:32-07:00</published>
    <updated>2011-08-31T09:42:36-07:00</updated>
    <link type="text/html" href="http://matharvard.ca/posts/2011/aug/30/ruby-on-rails-3-1-0-released/" rel="alternate" />
    <title>Ruby on Rails 3.1.0 Released</title>
    <summary type="html">&lt;p&gt;It&amp;rsquo;s time to upgrade.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;&lt;a href="http://twitter.com/rails/status/108740744306634752" target="_blank"&gt;Rails 3.1.0 is out&lt;/a&gt;! Check out the &lt;a href="http://guides.rubyonrails.org/3_1_release_notes.html" target="_blank"&gt;release notes&lt;/a&gt; and get hacking!&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;ve just finished upgrading this blog from RC 6 to the stable version. The asset pipeline took a little tinkering to get working, since I named my CSS files my self as opposed to using Rails&amp;rsquo; convention of &lt;code&gt;application&lt;/code&gt;. Otherwise it was a painless upgrade.&lt;/p&gt;</content>
    <author>
      <name>Mat Harvard</name>
    </author>
  </entry>
  <entry>
    <id>tag:matharvard.ca,2005:Post/10</id>
    <published>2011-08-22T18:39:41-07:00</published>
    <updated>2011-12-24T14:47:50-08:00</updated>
    <link type="text/html" href="http://matharvard.ca/posts/2011/aug/22/contact-form-in-rails-3/" rel="alternate" />
    <title>Contact form in Rails 3</title>
    <summary type="html">&lt;p&gt;A guide on building a form that when submitted, instead of being saved in a database, is sent through email.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;This is an updated version of a tutorial I originally wrote in 2008 on building a contact form with Ruby on Rails.&lt;/p&gt;

&lt;p&gt;The goal of this tutorial is to build a form that when submitted will validate and email the data.&lt;/p&gt;

&lt;h3&gt;Prerequisites&lt;/h3&gt;

&lt;p&gt;To simplify this, I&amp;rsquo;m just using Google Apps to manage email addresses. If you have your own email server just modify the settings as needed. To get started you&amp;rsquo;ll need:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;A Google Apps account, of course&lt;/li&gt;
  &lt;li&gt;Ruby on Rails 3.1.3 (&lt;code&gt;gem install rails&lt;/code&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;Configuring Rails for GMail&lt;/h3&gt;

&lt;p&gt;In an existing or new application, open &lt;code&gt;config/application.rb&lt;/code&gt;. Insert the following snippet in the &lt;code&gt;Application&lt;/code&gt; class.

&lt;pre&gt;&lt;code&gt;config.action_mailer.smtp_settings = {
  :address              =&amp;gt; &amp;quot;smtp.gmail.com&amp;quot;,
  :port                 =&amp;gt; 587,
  :domain               =&amp;gt; &amp;quot;yourdomain.dev&amp;quot;,
  :user_name            =&amp;gt; &amp;quot;from@yourdomain.dev&amp;quot;,
  :password             =&amp;gt; &amp;quot;Super-Secure-Password&amp;quot;,
  :authentication       =&amp;gt; :plain,
  :enable_starttls_auto =&amp;gt; true
}

config.action_mailer.default_url_options = {
  :host =&amp;gt; &amp;quot;yourdomain.dev&amp;quot;
}&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;Set the value of &lt;code&gt;:domain&lt;/code&gt; to the domain you&amp;rsquo;re using for Google Apps, and &lt;code&gt;:user_name&lt;/code&gt; and &lt;code&gt;:password&lt;/code&gt; to your Google Apps account credentials. In the second block replace &lt;code&gt;:host&lt;/code&gt; with the domain where the application is reachable from. The &lt;code&gt;:host&lt;/code&gt; option is used to ensure that all links in email templates generate full URLs.&lt;/p&gt;

&lt;h3&gt;The Message Model&lt;/h3&gt;

&lt;p&gt;To allow validation of the message, I create a model and just include &lt;code&gt;ActiveModel&lt;/code&gt;&amp;rsquo;s validations. Allowing the model to be written just like any other Rails model.&lt;/p&gt;

&lt;p&gt;Create the file &lt;code&gt;app/models/message.rb&lt;/code&gt;, or with a name of your choice. Make the file look similar to the following.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Message

  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming

  attr_accessor :name, :email, :subject, :body

  validates :name, :email, :subject, :body, :presence =&amp;gt; true
  validates :email, :format =&gt; { :with =&amp;gt; %r{.+@.+\..+} }, :allow_blank =&amp;gt; true
  
  def initialize(attributes = {})
    attributes.each do |name, value|
      send(&amp;quot;#{name}=&amp;quot;, value)
    end
  end

  def persisted?
    false
  end

end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is fairly self explanatory. A message can have a subject and body, as well as the name and email address of the sender. All of the fields are required, and the email address is verified with a regular expression.&lt;/p&gt;

&lt;h3&gt;The Mailer Model and Views&lt;/h3&gt;

&lt;p&gt;Run &lt;code&gt;rails g mailer NotificationsMailer&lt;/code&gt;. This generates &lt;code&gt;app/mailers/notifications_mailer.rb&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We&amp;#x27;ll want &lt;code&gt;notifications_mailer.rb&lt;/code&gt; to look similar to this snippet. Check out the &lt;code&gt;ActionMailer&lt;/code&gt; API for specifics on what&amp;rsquo;s happening here.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class NotificationsMailer &amp;lt; ActionMailer::Base

  default :from =&amp;gt; &amp;quot;noreply@youdomain.dev&amp;quot;
  default :to =&amp;gt; &amp;quot;you@youremail.dev&amp;quot;

  def new_message(message)
    @message = message
    mail(:subject =&amp;gt; &amp;quot;[YourWebsite.tld] #{message.subject}&amp;quot;)
  end

end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Replace &lt;code&gt;:to&lt;/code&gt;, &lt;code&gt;:from&lt;/code&gt; and &lt;code&gt;:subject&lt;/code&gt; with the address you&amp;rsquo;d like the email sent to, the address it&amp;rsquo;s being sent from (should be the one you configured the Rails application with), and the subject of the email.&lt;/p&gt;

&lt;p&gt;Create the file &lt;code&gt;app/views/notifications_mailer/new_message.text.erb&lt;/code&gt;.How the message looks is entirely up to you. Here&amp;rsquo;s an example of how it could be laid out.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Name: &amp;lt;%= @message.name %&amp;gt;

Email: &amp;lt;%= @message.email %&amp;gt;

Subject: &amp;lt;%= @message.subject %&amp;gt;

Body: &amp;lt;%= @message.body %&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;The Controller and View&lt;/h3&gt;

&lt;p&gt;Run &lt;code&gt;rails g controller contact&lt;/code&gt; and then open &lt;code&gt;app/controllers/contact_controller.rb&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The controller will only need two actions: &lt;code&gt;new&lt;/code&gt; and &lt;code&gt;create&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class ContactController &amp;lt; ApplicationController

  def new
    @message = Message.new
  end

  def create
    @message = Message.new(params[:message])
    
    if @message.valid?
      NotificationsMailer.new_message(@message).deliver
      redirect_to(root_path, :notice =&amp;gt; &amp;quot;Message was successfully sent.&amp;quot;)
    else
      flash.now.alert = "Please fill all fields."
      render :new
    end
  end

end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To get these actions working, open up &lt;code&gt;config/routes.rb&lt;/code&gt; and insert the following two lines.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;match &amp;#x27;contact&amp;#x27; =&amp;gt; &amp;#x27;contact#new&amp;#x27;, :as =&amp;gt; &amp;#x27;contact&amp;#x27;, :via =&amp;gt; :get
match &amp;#x27;contact&amp;#x27; =&amp;gt; &amp;#x27;contact#create&amp;#x27;, :as =&amp;gt; &amp;#x27;contact&amp;#x27;, :via =&amp;gt; :post&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;When a &lt;code&gt;GET&lt;/code&gt; request is made to &lt;code&gt;/contact&lt;/code&gt;, the &lt;code&gt;new&lt;/code&gt; action is called. When a &lt;code&gt;POST&lt;/code&gt; request is made to &lt;code&gt;/contact&lt;/code&gt;, the &lt;code&gt;create&lt;/code&gt; action is called.&lt;/p&gt;

&lt;p&gt;Create &lt;code&gt;app/views/contact/new.html.erb&lt;/code&gt;. As with the email template, this template is entirely up to you, I&amp;#x27;m only providing an example of what it could look like.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;%= form_for @message, :url =&amp;gt; contact_path do |form| %&amp;gt;
  &amp;lt;fieldset class=&amp;quot;fields&amp;quot;&amp;gt;
    &amp;lt;div class=&amp;quot;field&amp;quot;&amp;gt;
      &amp;lt;%= form.label :name %&amp;gt;
      &amp;lt;%= form.text_field :name %&amp;gt;
    &amp;lt;/div&amp;gt;
    
    &amp;lt;div class=&amp;quot;field&amp;quot;&amp;gt;
      &amp;lt;%= form.label :email %&amp;gt;
      &amp;lt;%= form.text_field :email %&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div class=&amp;quot;field&amp;quot;&amp;gt;
      &amp;lt;%= form.label :subject %&amp;gt;
      &amp;lt;%= form.text_field :subject %&amp;gt;
    &amp;lt;/div&amp;gt;
    
    &amp;lt;div class=&amp;quot;field&amp;quot;&amp;gt;
      &amp;lt;%= form.label :body %&amp;gt;
      &amp;lt;%= form.text_area :body %&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/fieldset&amp;gt;
  
  &amp;lt;fieldset class=&amp;quot;actions&amp;quot;&amp;gt;
    &amp;lt;%= form.submit &amp;quot;Send&amp;quot; %&amp;gt;
  &amp;lt;/fieldset&amp;gt;
&amp;lt;% end %&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;Try it&lt;/h3&gt;

&lt;p&gt;Start your &lt;code&gt;rails server&lt;/code&gt; and go to &lt;code&gt;/contact&lt;/code&gt;. Fill out the form and hit send. If everything was done correctly an email should arrive in the inbox of the address specified.&lt;/p&gt;
</content>
    <author>
      <name>Mat Harvard</name>
    </author>
  </entry>
  <entry>
    <id>tag:matharvard.ca,2005:Post/9</id>
    <published>2011-08-11T11:49:12-07:00</published>
    <updated>2011-08-11T11:53:38-07:00</updated>
    <link type="text/html" href="http://matharvard.ca/posts/2011/aug/11/git-push-with-specific-ssh-key/" rel="alternate" />
    <title>git-push with specific SSH key</title>
    <summary type="html">&lt;p&gt;Pushing to a remote repository where a specific SSH key is needed to authenticate is easy to accomplish.&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;I figured this was worth a post, as I&amp;rsquo;ve never ran into this problem before. I&amp;rsquo;ve been working on setting up a server, to which I connect using RSA. The standard name for an RSA key file is &lt;code&gt;id_rsa(.pub)&lt;/code&gt;. However, as I use my &amp;lsquo;standard&amp;rsquo; key elsewhere, I wanted to use a specific key for this server.&lt;/p&gt;

&lt;p&gt;Connecting via SSH to the server with the key is as simple as adding &lt;code&gt;-i /path/to/key&lt;/code&gt;. The problem arose when I needed to be able to push to a Git repository hosted on the server, and adding &lt;code&gt;-i&lt;/code&gt; to &lt;code&gt;git-push&lt;/code&gt; doesn&amp;rsquo;t work.&lt;/p&gt;

&lt;p&gt;The solution was to add a &lt;code&gt;Host&lt;/code&gt; directive to my &lt;code&gt;~/.ssh/config&lt;/code&gt; file. Then, use that &lt;code&gt;Host&lt;/code&gt; to connect to when &lt;code&gt;push&lt;/code&gt;&amp;rsquo;ing to the remote server.&lt;/p&gt;

&lt;p&gt;If it doesn&amp;rsquo;t exist, create the file &lt;code&gt;~/.ssh/config&lt;/code&gt;. Add the following to it, editing where necessary.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Host RemoteServer
  HostName remote-server.tld
  User git
  IdentityFile ~/.ssh/remoteserver_key&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Remember to reload SSH after creating this file. This example config would be the equivalent of running a command like &lt;code&gt;ssh git@remote-server.tld -i ~/.ssh/remoteserver_key&lt;/code&gt;. You can even run &lt;code&gt;ssh RemoteServer&lt;/code&gt; to test the connection out.&lt;/p&gt;

&lt;p&gt;In your Git repository, add a new remote repository. Here I&amp;rsquo;ve called it &lt;code&gt;origin&lt;/code&gt;, as the convention might have it.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git remote add origin RemoteServer:path/to/repository.git&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Instead of specifying a user &lt;code&gt;@&lt;/code&gt; a domain, it uses the name of the &lt;code&gt;Host&lt;/code&gt; in the SSH config. The &lt;code&gt;path/to/repository.git&lt;/code&gt; is relative, on the average system, that will probably point to &lt;code&gt;/home/git/path/to/repository.git&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Try running a &lt;code&gt;git push origin master&lt;/code&gt; to see if it works!&lt;/p&gt;
</content>
    <author>
      <name>Mat Harvard</name>
    </author>
  </entry>
  <entry>
    <id>tag:matharvard.ca,2005:Post/8</id>
    <published>2011-08-09T15:14:55-07:00</published>
    <updated>2011-10-03T21:27:38-07:00</updated>
    <link type="text/html" href="http://matharvard.ca/posts/2011/aug/9/interview-with-45pixels/" rel="alternate" />
    <title>Interview with 45pixels</title>
    <summary type="html">&lt;p&gt;My friend recently launched a website about design and the web and asked me to do an interview for him.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;My friend, Robby Klein, recently interviewed me for his website, &lt;a href="http://45pixels.com/" target="_blank"&gt;45pixels&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;!-- &lt;a href="http://45pixels.com/an-interview-with-web-developer-mat-harvard/" target="_blank"&gt;See the full post on 45pixels&lt;/a&gt; --&gt; (link removed temporarily)&lt;/p&gt;
</content>
    <author>
      <name>Mat Harvard</name>
    </author>
  </entry>
  <entry>
    <id>tag:matharvard.ca,2005:Post/7</id>
    <published>2011-08-04T22:14:46-07:00</published>
    <updated>2011-08-14T22:05:00-07:00</updated>
    <link type="text/html" href="http://matharvard.ca/posts/2011/aug/4/now-with-a-contact-form/" rel="alternate" />
    <title>Now with a contact form</title>
    <summary type="html">&lt;p&gt;I finished up my contact page today.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;I wrote up a little contact form for &lt;a href="/contact/" target="_blank"&gt;my contact page&lt;/a&gt;. Now it&amp;rsquo;s easy for anyone to get in touch with me. I&amp;rsquo;ll write up a tutorial on how it&amp;rsquo;s done soon.&lt;/p&gt;</content>
    <author>
      <name>Mat Harvard</name>
    </author>
  </entry>
  <entry>
    <id>tag:matharvard.ca,2005:Post/6</id>
    <published>2011-07-31T17:20:17-07:00</published>
    <updated>2011-08-08T02:05:02-07:00</updated>
    <link type="text/html" href="http://matharvard.ca/posts/2011/jul/31/exception-notification-for-rails-3/" rel="alternate" />
    <title>Exception notification for Rails 3</title>
    <summary type="html">&lt;p&gt;A short tutorial on how to get the &lt;code&gt;exception_notification&lt;/code&gt; plugin working on a Rails 3 application.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;Using the popular ExceptionNotification plugin has changed slightly in Rails 3. One thing to note is that the official repository has moved from the &lt;a href="http://github.com/rails" target="_blank"&gt;Ruby on Rails GitHub organization&lt;/a&gt; to &lt;a href="http://github.com/smartinez87/exception_notification" target="_blank"&gt;Sebastian Martinez&amp;rsquo;s account&lt;/a&gt;. Let&amp;rsquo;s get started.&lt;/p&gt;

&lt;p&gt;Add the gem to an applications Gemfile.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem 'exception_notification'&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then install the actual gem with either, &lt;code&gt;gem install exception_notification&lt;/code&gt;, or by running &lt;code&gt;bundle install&lt;/code&gt; from the application&amp;rsquo;s root.&lt;/p&gt;

&lt;p&gt;Open the environment configuration file for which the application requires exceptions being reported from, typically this is &lt;code&gt;config/environments/production.rb&lt;/code&gt;. Inside the application&amp;rsquo;s &lt;code&gt;configure&lt;/code&gt; block, place the following code, editing where necessary.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# For a full list of configurable options, see the gem&amp;#x27;s GitHub home page.
config.middleware.use ExceptionNotifier,
  :email_prefix =&amp;gt; &amp;quot;[Application Name] &amp;quot;,
  :sender_address =&amp;gt; %{ &amp;quot;Application Name&amp;quot; &amp;lt;noreply@application-name.ca&amp;gt; },
  :exception_recipients =&amp;gt; %w{ recipient.1@application-name.ca }&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;When the application is running on production, and assuming it&amp;rsquo;s set up with an email server, it will send the proper notification when an error occurs!&lt;/p&gt;</content>
    <author>
      <name>Mat Harvard</name>
    </author>
  </entry>
  <entry>
    <id>tag:matharvard.ca,2005:Post/5</id>
    <published>2011-07-27T08:18:08-07:00</published>
    <updated>2011-09-01T00:05:03-07:00</updated>
    <link type="text/html" href="http://matharvard.ca/posts/2011/jul/27/now-with-comments/" rel="alternate" />
    <title>Now with comments</title>
    <summary type="html">&lt;p&gt;It&amp;rsquo;s now possible to comment on posts.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;I&amp;rsquo;ve just launched a commenting system on my website. For now it&amp;rsquo;s quite simple: As long as the post is under two weeks old, comments will be accepted on it. Only a name and a comment is required. The email address and website fields are just there for &lt;a href="http://akismet.com/" target="_blank"&gt;Akismet&lt;/a&gt; and a link back to your site respectively.&lt;/p&gt;
</content>
    <author>
      <name>Mat Harvard</name>
    </author>
  </entry>
  <entry>
    <id>tag:matharvard.ca,2005:Post/4</id>
    <published>2011-07-21T18:28:52-07:00</published>
    <updated>2011-08-08T02:04:15-07:00</updated>
    <link type="text/html" href="http://matharvard.ca/posts/2011/jul/21/text-field-placeholder-in-coffeescript-using-jquery/" rel="alternate" />
    <title>Text field placeholder in CoffeeScript using jQuery</title>
    <summary type="html">&lt;p&gt;My first CoffeeScript in production.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;The HTML5 &lt;code&gt;placeholder&lt;/code&gt; attribute is great. Styling it, however, isn&amp;rsquo;t as great (it is possible though). I implemented my own in JavaScript. Conventions encouraged me to use &lt;a href="http://jquery.com/" target="_blank"&gt;jQuery&lt;/a&gt; and &lt;a href="http://jashkenas.github.com/coffee-script/" target="_blank"&gt;CoffeeScript&lt;/a&gt;. I&amp;rsquo;ll show what it looks like in both jQuery and CoffeeScript for the curious.&lt;/p&gt;

&lt;h3&gt;The Form&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;form action=&amp;quot;/posts/search/&amp;quot; method=&amp;quot;get&amp;quot; class=&amp;quot;search&amp;quot;&amp;gt;
  &amp;lt;input class=&amp;quot;placeholder&amp;quot; name=&amp;quot;q&amp;quot; type=&amp;quot;text&amp;quot; value=&amp;quot;Search&amp;quot; /&amp;gt;
&amp;lt;/form&amp;gt;&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;In jQuery&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;$(function(){
  $(&amp;quot;.search input&amp;quot;).focus(function() {
    if(this.value === &amp;quot;Search&amp;quot;) {
      this.value = &amp;quot;&amp;quot;;
      this.className = &amp;quot;textinput&amp;quot;;
    }
  });
  
  $(&amp;quot;.search input&amp;quot;).blur(function(){
    if(this.value === &amp;quot;&amp;quot;) {
      this.value = &amp;quot;Search&amp;quot;;
      this.className = &amp;quot;placeholder&amp;quot;;
    }
  });
});&lt;/code&gt;&lt;/pre&gt;

&lt;h3&gt;The same code in CoffeeScript&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;jQuery -&amp;gt;
  $(&amp;quot;.search input&amp;quot;).focus -&amp;gt;
    if @value == &amp;quot;Search&amp;quot;
      @value = &amp;quot;&amp;quot;
      @className = &amp;quot;textinput&amp;quot;
    
  $(&amp;quot;.search input&amp;quot;).blur -&amp;gt;
    if @value == &amp;quot;&amp;quot;
      @value = &amp;quot;Search&amp;quot;
      @className = &amp;quot;placeholder&amp;quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;My search form on the top&amp;ndash;right is running this exact code. It&amp;rsquo;s very simple: when the field is selected and the value is &amp;ldquo;Search&amp;rdquo;, the field is cleared and a class of &lt;code&gt;textinput&lt;/code&gt; is set (just changes the text colour); when the field is de&amp;ndash;selected and its value is blank, the value is reset to the default, &amp;ldquo;Search&amp;rdquo;, and the class is changed to &lt;code&gt;placeholder&lt;/code&gt; (again, just a colour change).&lt;/p&gt;

&lt;h3&gt;Resources&lt;/h3&gt;

&lt;p&gt;For the curious, RailsCasts has an episode outlining &lt;a href="http://railscasts.com/episodes/267-coffeescript-basics" target="_blank"&gt;the basics of CoffeeScript&lt;/a&gt;. Also, of course, is the &lt;a href="http://jashkenas.github.com/coffee-script/" target="_blank"&gt;CoffeeScript website&lt;/a&gt;.&lt;/p&gt;</content>
    <author>
      <name>Mat Harvard</name>
    </author>
  </entry>
  <entry>
    <id>tag:matharvard.ca,2005:Post/3</id>
    <published>2011-07-21T11:34:48-07:00</published>
    <updated>2011-08-08T02:03:52-07:00</updated>
    <link type="text/html" href="http://matharvard.ca/posts/2011/jul/21/my-nginx-config/" rel="alternate" />
    <title>My nginx config</title>
    <summary type="html">&lt;p&gt;An important piece behind this website.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;This post will hopefully start off a series about the internals of my website, its &amp;lsquo;colophon&amp;rsquo;, as it were. A little background information will help: this site runs on a Linode 512, it uses MySQL for data storage, &lt;a href="http://nginx.org/" target="_blank"&gt;nginx&lt;/a&gt; as a web server and &lt;a href="http://modrails.com/" target="_blank"&gt;Phusion Passenger&lt;/a&gt; backed by &lt;a href="http://rubyenterpriseedition.com/" target="_blank"&gt;Ruby Enterprise Edition&lt;/a&gt; for serving Rails. While there&amp;rsquo;s more in&amp;ndash;depth reasoning behind choosing these particular pieces of software, that&amp;rsquo;s best left for another post; to summarize, it&amp;rsquo;s what I &lt;em&gt;currently&lt;/em&gt; like.&lt;/p&gt;

&lt;p&gt;Time for some code. I would like to point out that I am not an expert on nginx. My configuration script may not be the most efficient, in fact it may even horribly offend anyone more learnt in the ways of nginx. When I finish the commenting system please do flame this post.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;server {
  server_name www.matharvard.ca matharvard.com www.matharvard.com;

  rewrite ^ $scheme://matharvard.ca$request_uri? permanent;
}

server {
  server_name matharvard.ca;

  access_log /var/www/matharvard.ca/log/access.log;
  error_log /var/www/matharvard.ca/log/error.log error;

  root /var/www/matharvard.ca/current/public;

  location / {
    rewrite ^/(.*)/$ /$1 break;
    try_files /system/maintenance.html /cache/$uri/index.html /cache/$uri.html $uri @passenger;
  }

  location /assets {
    try_files $uri @passenger
  }

  location /admin {
    try_files $uri @passenger;
  }

  location @passenger {
    passenger_enabled on;
  }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The first &lt;code&gt;server&lt;/code&gt; block is to point all requests to my preferred domain, &lt;code&gt;matharvard.ca&lt;/code&gt;, and strip the &lt;code&gt;www&lt;/code&gt; sub&amp;ndash;domain.&lt;/p&gt;

&lt;p&gt;In the second server block, it sets up the access and error logs, and sets the &lt;code&gt;root&lt;/code&gt; of the site to the &lt;code&gt;public&lt;/code&gt; directory of my Rails app.&lt;/p&gt;

&lt;p&gt;The first location block is meant for the public facing side of the website. The re&amp;ndash;write rule inside it strips any trailing slash from the URL (for caching purposes). &lt;code&gt;try_files&lt;/code&gt; is the new alternative to the old (&lt;a href="http://wiki.nginx.org/IfIsEvil" target="_blank"&gt;and discouraged&lt;/a&gt;) method of a series of &lt;code&gt;if&lt;/code&gt; statements checking for the existence of files. First, it looks to see if I&amp;rsquo;ve disabled the website by uploading the maintenance page. Second, it checks to see if the user is attempting to view the index page, if they are, it serves the cached version of the page. Third, it checks to see if the page the user requested exists in the cache (this is for all pages except the index). The fourth part is for static assets, such as images or CSS files, it tries to serve those directly. Lastly, if the requested file doesn&amp;rsquo;t exist in the cache or otherwise, it sends the request to my Rails app for processing. Which in turn will probably create the cached version of the page for the next user that requests it.&lt;/p&gt;

&lt;p&gt;The second &lt;code&gt;location&lt;/code&gt; block allows assets to be served, from the web server or my Rails app, even if the maintenance page is up, this is because&amp;hellip;&lt;/p&gt;

&lt;p&gt;The third &lt;code&gt;location&lt;/code&gt; block, for the administration panel, is accessible even if the public site is disabled. There&amp;rsquo;s no need for caching, so if the request isn&amp;rsquo;t for an asset, it&amp;rsquo;s sent straight to Rails.&lt;/p&gt;

&lt;h3&gt;Improvements&lt;/h3&gt;

&lt;p&gt;Is something wrong with it? I did a lot of searching for the &amp;lsquo;proper&amp;rsquo; way to configure nginx, but I don&amp;rsquo;t claim that my code is the best in any way. Feel free to share your experience in the comments.&lt;/p&gt;
</content>
    <author>
      <name>Mat Harvard</name>
    </author>
  </entry>
  <entry>
    <id>tag:matharvard.ca,2005:Post/2</id>
    <published>2011-07-20T13:16:26-07:00</published>
    <updated>2011-08-08T02:03:27-07:00</updated>
    <link type="text/html" href="http://matharvard.ca/posts/2011/jul/20/tumblelog-on-rails-and-mongodb/" rel="alternate" />
    <title>Tumblelog on Rails and MongoDB</title>
    <summary type="html">&lt;p&gt;I&amp;rsquo;ve been working on a little app in the past month.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;I had an idea to turn my website into a tumblelog a while back. That idea ended up taking the shape of a GitHub project called, &lt;a href="http://github.com/matharvard/theorangeseed" target="_blank"&gt;theorangeseed&lt;/a&gt;. It was built with Ruby on Rails and used MySQL to store posts. I used one model, &lt;code&gt;Post&lt;/code&gt;, to store the different post types (something I still think as clever today). I learned a few things from it, but ultimately it ended up as wasted space on my hard-drive.&lt;/p&gt;

&lt;p&gt;Time passed and technology progressed. MongoDB was becoming a hot topic. With the introduction of MongoMapper and Mongoid ORM&amp;rsquo;s for MongoDB it became an area of interest within the Rails community. Which is where I heard about it. I wrote a few applications to get a feel for both of the ORM&amp;rsquo;s. They were more or less the same, each with its own pros and cons but mainly application specific (what I&amp;rsquo;ve found anyway).&lt;/p&gt;

&lt;p&gt;Over the last couple months I&amp;rsquo;ve put some time into re&amp;ndash;creating theorangeseed, this time using MongoDB. At this time I don&amp;rsquo;t have any solid plan for the future of the project. I may at some point run a website with it, but for now it&amp;rsquo;s available on GitHub, &lt;a href="http://github.com/matharvard/waves" target="_blank"&gt;here&lt;/a&gt;. I named it &amp;lsquo;Waves&amp;rsquo; after a trip I took last summer to visit a friend in Virgina Beach, VA. We went to see a kite boarding competition in Waves, NC. It should be straightforward to get running. The only requirement involving more than a &lt;code&gt;bundle install&lt;/code&gt; is having MongoDB installed.&lt;/p&gt;

&lt;p&gt;Waves allows text, links, chats, code snippets, quotes, videos and images (through GridFS) to be posted. It has a basic authentication system thanks to &lt;a href="http://github.com/thoughtbot/clearance" target="_blank"&gt;Clearance&lt;/a&gt; by Thoughtbot (with modifications to support MongoDB/MongoMapper). It&amp;rsquo;s future is un&amp;ndash;decided but I know it could use theme support and better administrative features.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://github.com/matharvard/waves" target="_blank"&gt;Check out Waves on GitHub&lt;/a&gt;&lt;/p&gt;
</content>
    <author>
      <name>Mat Harvard</name>
    </author>
  </entry>
  <entry>
    <id>tag:matharvard.ca,2005:Post/1</id>
    <published>2011-07-19T20:55:34-07:00</published>
    <updated>2011-08-08T02:03:07-07:00</updated>
    <link type="text/html" href="http://matharvard.ca/posts/2011/jul/19/powered-by-spotify/" rel="alternate" />
    <title>Powered by Spotify</title>
    <summary type="html">&lt;p&gt;What was, what is, and some things that will be.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;It doesn&amp;rsquo;t take very long to write a &amp;lsquo;finished&amp;rsquo; application with a framework such as Ruby on Rails or Django (Rails being my preference right now). So I decided to just start from scratch. After choosing from too many design mock&amp;ndash;ups to count, I settled on this simple and clean layout. It has room to grow in the future, something that I aimed for from the beginning, in the case I add more features.&lt;/p&gt;

&lt;h3&gt;50% up front, the other half later&lt;/h3&gt;

&lt;p&gt;The site isn&amp;rsquo;t complete. I built only what I needed to launch. My &lt;a href="/work/" target="_blank"&gt;work&lt;/a&gt; and &lt;a href="/contact/" target="_blank"&gt;contact&lt;/a&gt; pages are both incomplete. The search feature is minimal. There are no comments on posts. The administration interface is mostly a wireframe and leaves a lot to be desired. These are all things I can live with.&lt;/p&gt;

&lt;p&gt;What matters the most is that I&amp;rsquo;m able to write. I figured out over the years that I&amp;rsquo;ll never be content with my personal website. There&amp;rsquo;s always something that I want to work on, improve, or that I just plain don&amp;rsquo;t like. Given time I&amp;rsquo;ll finish off the features that are missing. It will be an on&amp;ndash;going project.&lt;/p&gt;

&lt;h3&gt;Looking ahead&lt;/h3&gt;

&lt;p&gt;Over the next week my goal is to finish off a couple more key features. I&amp;rsquo;d like to write about the building of my website as well. I may release the source code at some point, but it&amp;rsquo;s so simple that I&amp;rsquo;m sure someone could create something of the same complexity quite easily.&lt;/p&gt;

&lt;p&gt;For now, if any questions are raised, I&amp;rsquo;ve provided a couple of ways to contact me &lt;a href="/contact/" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;Powered by&amp;hellip;&lt;/h3&gt;

&lt;p&gt;No, it&amp;rsquo;s not actually powered by &lt;a href="http://spotify.com/" target="_blank"&gt;Spotify&lt;/a&gt;, though I wish it was (I actually named the application &lt;code&gt;SmallWaves&lt;/code&gt;). I have to mention how incredible Spotify is. I&amp;rsquo;m sure I&amp;rsquo;ll have more words to say about it at a later date. For now, just go check it out!&lt;/p&gt;
</content>
    <author>
      <name>Mat Harvard</name>
    </author>
  </entry>
</feed>

