logo
  • Jobs
  • About Me
  • Contact
  • Home

Archive for the ‘Uncategorized’ Category

« Previous Entries
Next Entries »

DHH at Startup School 08

Yesterday, I sat and listened to David Heinemeir Hansson’s presentation at Startup School 2008. Most people know DHH as the creator of Ruby on Rails, but he is also a co-founder of partner at 37signals, which could very easily be considered a successful startup. This is an amazing talk, filled with excellent insight into what is needed to create a profit.

Hint: you *DONT* have to create the next Facebook or MySpace to be a wildly successful startup. You just have to find something that someone else is doing and do it just a little better. The talk is ~30 minutes long and is absolutely worth your time to watch.

Fair warning: in typical DHH fashion, there are a few f-bombs sprinkled in throughout the talk. You may want to wear headphones. :)

4 Comments

Cappin’ that Stat - Solaris edition

Some time ago, I saw a post on err the blog that detailed how to use Capistrano to inject your site’s google analytics javascript at deploy time. The major advantage to this is that you dont run up your site stats while developing your site. While developing, it’s empty, and when you run a cap deploy, it places the javascript right before the closing body tag. Brilliance, if you ask me … until you try the posted after_symlink task on a Solaris box.

Solaris’s version of sed does not support the -i (in-place) option. You could create a nasty script that does all the intermediate saving for you, but I chose to go a different route … perl.

Perl has some options that can be passed to it which allow it to function on sed scripts. If you are deploying your Rails application to a Solaris environment, you can use this Capistrano task instead:

task :after_symlink, :roles => :app do
  stats = < <-JS
	<script src="http://www.google-analytics.com/urchin.js" type="text/javascript" charset="utf-8">
 
	<script type="text/javascript" charset="utf-8">
		_uacct = "YOUR-TRACKING-CODE";
		urchinTracker();
	</script>
  JS
 
  layout = "#{current_path}/app/views/layouts/application.rhtml"
  run "perl -pi -e 's??#{stats}?' #{layout}"
end

My stats should hopefully be a bit more relevant with this little gem.

1 Comment

CMD-K for searching in Safari

Using Firefox on my daytime PC and Safari on my evening PC (MBP), I’ve suffered a bit of schizophrenia when it comes to keyboard shortcuts. To get to the Google search box in Safari, I would hit CMD-L (to get to the location bar), and then hit TAB to get to the search box. I very much wanted a CMD-K shortcut, similar to what I use in Firefox.

Earlier today, I found how to do this:

  • Open System Preferences > Keyboard & Mouse > Keyboard Shortcuts
  • Click the add button in the lower left corner
  • Select Safari from the application drop down menu
  • Enter “Google Search…” for the menu title (the … is made by clicking OPTION-;)
  • Focus on the Keyboard Shortcut textbox and press CMD-K
  • Select add and restart Safari

Thanks to the folks over at 5thirtyone for this tip.

8 Comments

Generating URLs with ActionMailer

ActionMailer is a very handy class for sending emails from your rails application. However, the problem that typically arises is the sending of links to your site via rails using the url_for method. Acording to the API documentation, this is because the mailer instance does not have any context about the incoming request. The API documentation recommends passing the host to the url_for parameter, like this:

url_for(:host => "www.myproductionsite.com", :controller => :home, :action => :index)

However, when using multiple url_for calls in a model, this can lead to a violation of DRY. Therefore, the typical resolution to this has been to add some declarations to your class, like this:

class Notification < ActionMailer::Base
  default_url_options[:host] = "www.myproductionsite.com"
end

I dont really care for this approach, as it locks my model into operating under the assumptions of a particular environment. I am unable to verify the links in my development or test environments without some string manipulation. A little effort led me to this approach, which so far seems to be much better. Instead of declaring the default_url_options in the ActionMailer model, I’m including them in config/environments/*.rb in this way.

# development.rb and test.rb
class ActionMailer::Base
  default_url_options[:host] = "localhost"
  default_url_options[:port] = 3000
end
 
# production.rb
class ActionMailer::Base
  default_url_options[:host] = "www.myproductionsite.com"
end

I am taking advantage of the environments file to give me the benefits of custom url options based on the environment that I am currently executing in. This is precisely what these files were designed for.

1 Comment

Lazy Web Request: Google Reader and comments

I have been using Google Reader for quite some time now and thoroughly enjoy the feed synchronization that comes from this hosted solution. Additionally, I very much enjoy being able to zip through my feeds. I find myself trying to j and k’ing through other lists of data as well. Unfortunately, it doesnt always work. But, I digress…

The real point of this post is to ask how other people keep track of the comments that they have posted to articles. Currently, what I’m doing is starring the article, and then I go back through to locate the ones I’ve commented on to see if there’s further discussion. This seems *much* too manual, and surely there is a better way to do this.

Here’s where I solicit your help, dear reader… Let me know in the comments how you keep track of articles that you’ve posted comments to and how you keep the conversation going. Thanks in advance for your ideas.

6 Comments

Blasting open source

In the latest installment of the Elegant Code Cast, David Starr talks with Darrel Carver, a local .NET developer and member of the Elegant Code group. I found the talk quite fascinating, but do want to pick on Darrel for one of his comments.

Repeatedly through the podcast, Darrel mentioned that open source is guilty of continuing the re-invention of software, simply because someone may not like the project owner, or that just one additional feature is needed. After all, as Darrel puts it, why do we need 10 IOC containers? While this may certainly be true, I do not think that it was fair for Darrel to state that this was purely a trait of open source.

Microsoft itself is guilty of continuing and enabling this behavior. Rather than reach to the open source community and leverage the great tools that are already there, Microsoft insists on rebranding tools that have been created in the open source space (NAnt/MSBuild, MonoRail/System.Web.MVC, NUnit/MSUnit, NDoc/Sandcastle, etc). They do this because it is far easier to have enterprises adopt a toolset when it is supported by a company like Microsoft. What I fail to see is why enterprises that use Java do not have the same problems. I also fail to see how the open source community can be faulted without mention of the identical behavior from the platform vendor. After all, had we been blindly following the tools given to us by a vendor, many of us would have never even been exposed to IOC, xUnit or many of the other principles that ALT.NET developers hold dear.

The primary difference is that the majority of different open source projects add their own value in ways. Take for example StructureMap vs Castle Windsor. The essence of both is the same; they are both IOC containers. StructureMap has been around a bit longer, but Castle Windsor has many more features, including interceptors, facilities and such. These diverse feature sets are where the value of multiple projects comes to bear. However, simply re-branding the best of breed projects does nothing to add value.

It is these re-branded projects that make Darrel’s point: many projects that do not add value do much to clutter up the developers toolbox and should be eliminated.

26 Comments

Ruby strings and is_int?

Lately, I’ve found myself needing to do some parameter checking to ensure that appropriate data makes it back to my models when doing finds. Using the will_paginate plugin allows me to very easily do paging on my model data. I simply have to provide the page to the options hash.

class Model < ActionRecord::Base
  def self.search(parameter, page)
    paginate :per_page => 10, :page => page,
             :conditions => ['model.parameter = ?', parameter]
  end
end

The problem here is that some people are trying to pass in URLs as the page parameter, causing exceptions to be raised. I’ve installed Jamis Buck’s ExceptionNotifier plugin and this is informing me via email of every exception encountered in the application. On a side note, I cannot recommend this plugin enough if you want to see where your application is being used incorrectly. I’ve found numerous edge cases with this plugin and urge every Rails installation to take advantage of it.

I wrote a spec for what I was after that looked like this:

describe Model do
  it "should convert the page number to one if an integer is not passed" do
    Model.should_receive(:paginate).with(hash_including(:page => "1"))
    Model.search("parameter", "some_invalid_page_number")
  end
end

Of course this test failed, so I set out to make it pass. What I really needed in this case was a way to reset the page parameter to an integer value if it was not an integer. I scoured the Ruby and Rails documentation but did not find anything built in to the framework.

Having seemingly no other option but to monkey-patch the string class, I ended up with this:

class String
  def is_int?
    self =~ /^[-+]?[0-9]*$/
  end
end

and the first line of the search method in my model looks like this:

page = "1" if not page.is_int?

My specification passed, but surely there’s a better way. I really do not want to monkey patch classes if I dont need to.

6 Comments

Investigating RSpactor

RSpactor is a command line tool for OSX Leopard that does basically the same thing as autotest, which is to re-run your specs any time one of your application files changes.

The reason that it only works on Leopard is the same thing that makes it better than autotest at this point. It uses the filesystem events (FSEvent on Leopard) exposed by RubyCocoa. This makes it much, much faster than using the file notification system used by autotest. It’s saved my MBP fan from spinning up when I go through a development session. Additionally, Growl support is built in so you have very nice notifications available for when your tests pass or fail.

Since I rebuilt the version of Ruby that was included with Leopard, I ended up having to manually install the RubyCocoa libraries. Thankfully though, this was relatively straightforward as well. If you’re running a stock Leopard install, you wont need to do anything other than:

superbia:~ matt$ sudo gem install rspactor
superbia:~ matt$ cd /path/to/your/app && rspactor

If you’re using autotest currently and are on OSX Leopard, do yourself a favor and check this tool out.

No Comments

Has it really been five years?

Five years ago today, I launched this blog as a way to work on my writing skills as well as give back a little to the community that I’ve learned so much from. It’s been a very fun and interesting ride. I’ve much enjoyed being able to provide technical information to my audience.

A recent review of my Google Analytics account showed the following posts as the most popular on this site. Interestingly enough, the single most popular post on this site has no technical nature whatsoever. The rest I’ve noticed are very tactical in nature and are probably a result of having almost 75% of my traffic driven by search engines.

  • Escape from the Crimson Room
  • Submitting ASP.NET form with the ENTER key
  • Date validation in ASP.NET
  • Replacing notepad in Windows Vista
  • Serializing an IDictionary object
  • Windows Vista and the screen saver
  • Executing a SQL script using ADO.NET

Over the past five years, I’ve created 757 posts that have generated 1378 comments. I’ve had visits from 183 countries/territories across the globe. This has far surpassed anything that I originally thought would happen with this site. After all, who would want to listen to a geek from Boise, Idaho? My goal for this site for the next five years is to continue to provide technical, how-to information. I’d also like to increase the social aspects of the site and look forward to posting things that cause conversations to occur on this site as well as others.

Here’s to five more years. Thank you to all of my readers. You mean more to me than I can ever express. Keep reading and I will keep writing.

1 Comment

Twitter

A while back I posted that I didn’t really get Twitter. However, recently, my synapses started firing around this concept. I’m just starting to look at it as a very intriguing public form of instant messaging.

Im mattberther on twitter.com. Drop by and say hello.

No Comments
« Previous Entries
Next Entries »
Social
  • mattberther on twitter
Syndication
Archives
  • November 2008
  • September 2008
  • August 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • March 2005
  • February 2005
  • January 2005
  • December 2004
  • November 2004
  • October 2004
  • September 2004
  • August 2004
  • July 2004
  • June 2004
  • May 2004
  • April 2004
  • March 2004
  • February 2004
  • January 2004
  • December 2003
  • November 2003
  • October 2003
  • September 2003
  • August 2003
  • July 2003
  • June 2003
  • May 2003
  • April 2003
  • March 2003
Jobs
mattberther.com © 2003 - 2008