<?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" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en-US">
  <title>HeyCarsten - Home</title>
  <id>tag:heycarsten.com,2009:mephisto/</id>
  <generator uri="http://mephistoblog.com" version="0.8.0">Mephisto Drax</generator>
  
  <link href="http://heycarsten.com/" rel="alternate" type="text/html" />
  <updated>2009-05-23T15:55:47Z</updated>
  <link rel="self" href="http://feeds.feedburner.com/heycarsten" type="application/atom+xml" /><entry xml:base="http://heycarsten.com/">
    <author>
      <name>Carsten Nielsen</name>
    </author>
    <id>tag:heycarsten.com,2009-05-22:114</id>
    <published>2009-05-22T06:13:00Z</published>
    <updated>2009-05-23T15:55:47Z</updated>
    <category term="cell phone carriers" />
    <category term="rant" />
    <category term="sms" />
    <link href="http://feedproxy.google.com/~r/heycarsten/~3/YST9dCJIkms/what-if-sms-was-your-internet-connection" rel="alternate" type="text/html" />
    <title>What If SMS Was Your Internet Connection?</title>
<content type="html">
            &lt;p&gt;&lt;small&gt;&lt;strong&gt;WARNING:&lt;/strong&gt; This is a total rant, I don’t know how cell networks actually work. If you know what you are talking about please explain why it makes sense to charge 15 cents per message in the comments.&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;There are a lot of things that piss me off about Canada’s cellphone providers, and lots of people have touched on them in detail already. What pisses me off the most though is what they charge for SMS messaging.&lt;/p&gt;

&lt;p&gt;SMS is low priority data, meaning it gets there when it gets there. The total SMS traffic for Rogers per day might amount to 2 gigabytes. It’s almost obscene that they even charge us to send SMS messages at all. Let’s look at this a different way, what if you relied on SMS as your internet connection?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A packet is 160 bytes plus some overhead, let’s say &lt;strong&gt;256 bytes&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Lets say on average it takes 4 seconds to go from source to destination: (256 / 4) = &lt;strong&gt;64 bytes per second&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;That translates to &lt;strong&gt;512 bps&lt;/strong&gt; (bits per second)&lt;/li&gt;
&lt;li&gt;512 bps is about &lt;strong&gt;90 times slower&lt;/strong&gt; than your average 56k modem (assuming an actual connection speed of 46000 bps) and about 5 times slower then your 2400 baud modem circa 1987.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So your Internet connection would be ridiculously slow and unreliable, but how much would it cost? Well let’s assume Rogers’ standard rate of 15 cents per message (or every 256 bytes in our case.) Last month I used 18 GB of download bandwidth and 4 GB of upload bandwidth so it would have cost me &lt;strong&gt;$138,412.03&lt;/strong&gt;… Oh, and it would have taken me &lt;strong&gt;719 years&lt;/strong&gt; to download.&lt;/p&gt;
          </content>  <feedburner:origLink>http://heycarsten.com/2009/5/22/what-if-sms-was-your-internet-connection</feedburner:origLink></entry>
  <entry xml:base="http://heycarsten.com/">
    <author>
      <name>Carsten Nielsen</name>
    </author>
    <id>tag:heycarsten.com,2008-12-17:117</id>
    <published>2008-12-17T05:00:00Z</published>
    <updated>2009-05-04T14:53:45Z</updated>
    <category term="javascript" />
    <category term="left" />
    <category term="prototype" />
    <category term="rails" />
    <category term="ruby" />
    <link href="http://feedproxy.google.com/~r/heycarsten/~3/tl-adZoFu2o/unobtrusive-auto-completing-text-fields-with-prototype-scriptaculous" rel="alternate" type="text/html" />
    <title>Unobtrusive Auto-Completing Text Fields With Prototype &amp; Scriptaculous</title>
<content type="html">
            &lt;p&gt;I recently had to add some auto completion behavior to a few text fields on &lt;a href="http://learnhub.com"&gt;LearnHub&lt;/a&gt;. Rails used to have a view helper for this baked-in, it’s a &lt;a href="http://github.com/rails/auto_complete/tree/master"&gt;plugin&lt;/a&gt; now, but I never really liked working with it. I hate farting &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; elements throughout my HTML for functionality like this, it looks dirty and just feels wrong to me.&lt;/p&gt;

&lt;p&gt;My goal was to go from something nasty like this:&lt;/p&gt;

&lt;pre&gt;&lt;code class="html"&gt;
&amp;lt;input type='text' name='school[name]' id='school_name_1' /&amp;gt;
&amp;lt;div class='autocompleter-choices' id='school_name_1_completer'&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;script type='text/javascript'&amp;gt;
//&amp;lt;![CDATA[
new Ajax.Autocompleter(
  'school_name_1',
  'school_name_1_completer',
  '/schools/autocompleter/search',
  { 'paramName' : 'q' }
);
//]]&amp;gt;
&amp;lt;/script&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To something simple and elegant like this:&lt;/p&gt;

&lt;pre&gt;&lt;code class="html"&gt;
&amp;lt;input type='text' name='school[name]' autocompleter='/schools/autocompleter/search' /&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;My solution was to do it unobtrusively with some straight-forward Javascript:&lt;/p&gt;

&lt;pre&gt;&lt;code class="javascript"&gt;
Helpers.TextFieldAutocompleters = {

  init : function()
  {
    $$('input[autocompleter]').each(function(input) {
      var url = input.readAttribute('autocompleter');
      var container = new Element('div', { 'class' : 'autocompleter-choices' });
      input.insert({ 'after' : container });
      new Ajax.Autocompleter(input.identify(), container.identify(), url, {
        'paramName' : 'q'
      });
    });
  }

}

Event.observe(window, 'load', function() {
  Helpers.TextFieldAutocompleters.init();
});

&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Lets have a quick look at what I am doing here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I use Prototype’s &lt;a href="http://www.prototypejs.org/api/utility/dollar-dollar"&gt;$$&lt;/a&gt; utility method to grab all of the &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; elements on the page that have an &lt;code&gt;autocompleter&lt;/code&gt; attribute.&lt;/li&gt;
&lt;li&gt;I insert an anonymous &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; below each &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; to contain the &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt; of results returned by the server.&lt;/li&gt;
&lt;li&gt;I use Prototype’s &lt;a href="http://prototypejs.org/api/element/identify"&gt;Element.identify()&lt;/a&gt; method to automatically generate DOM IDs for the anonymous/potentially anonymous container &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; elements.&lt;/li&gt;
&lt;li&gt;I create a new Scriptaculous &lt;a href="http://github.com/madrobby/scriptaculous/wikis/ajax-autocompleter"&gt;Ajax.Autocompleter&lt;/a&gt; that will submit to the path indicated in the &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; element’s &lt;code&gt;autocompleter&lt;/code&gt; attribute and use &amp;lsquo;&lt;code&gt;q&lt;/code&gt;&amp;rsquo; as the param name.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That’s all there is to it!&lt;/p&gt;

&lt;h3&gt;The Rest Of It&lt;/h3&gt;

&lt;p&gt;This is the controller action:&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;
def autocompleter_search
  @schools = School.name_like(params[:q]).all(:limit =&gt; 8)
  t = []
  t &amp;lt;&amp;lt; '%ul'
  t &amp;lt;&amp;lt; '  - @schools.each do |school|'
  t &amp;lt;&amp;lt; '    %li= highlight h(school), h(params[:q])'
  template = t.join("\n")
  respond_to do |format|
    format.js   { render :inline =&gt; template, :type =&gt; :haml }
    format.html { render :inline =&gt; template, :type =&gt; :haml }
  end
end

&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The named_scope I’m using for the above School finder:&lt;/p&gt;

&lt;pre&gt;&lt;code class="ruby"&gt;
named_scope :name_like, lambda { |name|
  { :conditions =&gt; ['`name` LIKE ?', "%#{name}%"],
    :order =&gt; '`name` ASC' } }

&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And the styles I use for the choices list:&lt;/p&gt;

&lt;pre&gt;&lt;code class="sass"&gt;
.autocompleter-choices
  :background #fff
  :border 1px solid #8caddd
  :margin-top -1px
  ul
    :padding 2px
    li
      :padding 3px
      em
        :font-weight bold
        :font-style normal
      &amp;.selected
        :background #f6eda9

&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That didn’t hurt one bit!&lt;/p&gt;
          </content>  <feedburner:origLink>http://heycarsten.com/2008/12/17/unobtrusive-auto-completing-text-fields-with-prototype-scriptaculous</feedburner:origLink></entry>
  <entry xml:base="http://heycarsten.com/">
    <author>
      <name>Carsten Nielsen</name>
    </author>
    <id>tag:heycarsten.com,2008-10-25:75</id>
    <published>2008-10-25T21:00:00Z</published>
    <updated>2008-10-25T21:06:09Z</updated>
    <category term="inspiration" />
    <category term="left" />
    <category term="right" />
    <category term="thought exercises" />
    <link href="http://feedproxy.google.com/~r/heycarsten/~3/fsc8cZWkRYA/waking-up-the-brain" rel="alternate" type="text/html" />
    <title>Waking Up The Brain</title>
<content type="html">
            &lt;p&gt;Before the first revision of a comp or the first passed test, I find the biggest problem I face is finding a way to harness my creative wit and direct it towards a new problem. Getting focused when there are all kinds of ideas, deadlines, demands and expectations floating around your noggin is a must, but it’s not always easy.&lt;/p&gt;

&lt;p&gt;I’m going to share some methods that I use to get back on track and focus my creative and analytical energy. Sometimes I follow my process start to end and sometimes I jump straight to brainstorming, it depends on my state of mind at the time. I hope you enjoy!&lt;/p&gt;

&lt;h2&gt;Contour Drawing&lt;/h2&gt;

&lt;p&gt;&lt;img title="A section of a blind contour drawing of my Dyson vacuum." src="http://heycarsten.com/assets/2008/10/25/contour-drawing.jpg" alt="" /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.google.com/search?q=%22contour+drawing%22"&gt;Contour drawing&lt;/a&gt; is often my first step when I’ve been extremely focused on other things and in need of a reset. I find it really cleans my mind’s slate, sort of like shaking an Etch-A-Sketch. I like to start off blind contour and then move my way to modified contour.&lt;/p&gt;

&lt;h2&gt;Freestyle (Writing &amp;amp; Drawing)&lt;/h2&gt;

&lt;p&gt;&lt;img title="A section of a work I did many years ago depicting the difference between the left and right sides of the brain." src="http://heycarsten.com/assets/2008/10/25/left-to-right.jpg" alt="" /&gt;&lt;/p&gt;

&lt;p&gt;I find it necessary to turn up the &lt;a href="http://twitter.com/_why"&gt;crazy&lt;/a&gt; and focus in on something new and offbeat to get myself in the mood for some design and analysis. I usually put on my headphones and queue up some music. I start writing and doodling arbitrarily at first, and then gradually transition towards the topic I’m going to be brainstorming.&lt;/p&gt;

&lt;p&gt;I sometimes write a dialog between two characters with opposing opinions or about a feeling or experience that I’ve never felt or had. I will often draw haphazardly; creating a form and then just adding other forms onto it transforming it into whatever. Sometimes if I really need to think differently, I’ll draw a &lt;a href="http://www.google.com/search?q=%22Rube+Goldberg+Machine%22"&gt;Rube Goldberg machine&lt;/a&gt; in some form.&lt;/p&gt;

&lt;p&gt;They key with freestyle I find is to avoid stopping and thinking about something else so you don’t interrupt your flow of ideas. Freestyle is a preparatory process for me that leads to brainstorming.&lt;/p&gt;

&lt;h2&gt;Brainstorming&lt;/h2&gt;

&lt;p&gt;&lt;img title="A portion of a brainstorming session for LearnHub." src="http://heycarsten.com/assets/2008/10/25/brainstorm.jpg" alt="" /&gt;&lt;/p&gt;

&lt;p&gt;After contour drawing and/or some freestiling, I start focusing in again. I feel refreshed and I find it much easier to form and output tangible ideas. At this stage I’ll use a little color to spice things up, but often it’s just black ink on layout stock. You could get fancy and use a four color ballpoint like Ed Fella, but that seems like a lot of work to me.&lt;/p&gt;

&lt;p&gt;Brainstorming for me is sort of like a formal form of freestyle, I force myself to stay on topic, and I create things that I might show other people. These range from the infamous word cloud, to comprehensive wireframes, and sometimes even code. It’s not uncommon for me to draw a wireframe and also the structure of it’s markup.&lt;/p&gt;

&lt;p&gt;Often times I brainstorm my initial ideas independently and in silence. However, when I’m far enough along in the creative process I like to share the activity with other designers and developers, and sometimes friends or other coworkers.&lt;/p&gt;

&lt;h2&gt;Final Thoughts&lt;/h2&gt;

&lt;p&gt;&lt;img title="Sometimes you've just gotta say it." src="http://heycarsten.com/assets/2008/10/25/frig.jpg" alt="" /&gt;&lt;/p&gt;

&lt;p&gt;I found it tough at first to be this raw. It wasn’t easy until I came to the realization that it’s okay to be bogus. Just because I draw or write something doesn’t automatically make it a direct reflection of who I am and I don’t have to put everything I make on public display. After those realizations I was free to experiment, and able to let myself wander areas of my mind that I’d never been.&lt;/p&gt;
          </content>  <feedburner:origLink>http://heycarsten.com/2008/10/25/waking-up-the-brain</feedburner:origLink></entry>
  <entry xml:base="http://heycarsten.com/">
    <author>
      <name>Carsten Nielsen</name>
    </author>
    <id>tag:heycarsten.com,2008-10-10:69</id>
    <published>2008-10-10T16:45:00Z</published>
    <updated>2008-10-10T17:54:18Z</updated>
    <category term="inspiration" />
    <category term="left" />
    <category term="right" />
    <category term="story" />
    <link href="http://feedproxy.google.com/~r/heycarsten/~3/x_1fRagz0c0/seven-ways-to-get-out-of-the-basement" rel="alternate" type="text/html" />
    <title>Seven Ways To Get Out of The Basement</title>
<content type="html">
            &lt;p&gt;I am really happy where I am right now. It’s hard to think that not too long ago, I was in my parents’ basement dreaming of working in the big city and building an awesome product — stuck in a rut of sorts. I’m going to share the values that I feel helped me get out of that rut and move beyond the basement.&lt;/p&gt;

&lt;h2&gt;1. You Must Have Passion&lt;/h2&gt;

&lt;p&gt;Passion is your fuel, you need passion! It’s the only way you will be disciplined enough to be able to fight down the odds. If you’re not thinking about it day and night, living and breathing it, then it might not be for you. Passionate people enjoy the company of other passionate people, you want to know passionate people… see where I’m going with this?&lt;/p&gt;

&lt;h2&gt;2. ‘No’ is a Statement, Not An Answer&lt;/h2&gt;

&lt;p&gt;Before I decided to take a different approach I tried to get into YSDN two times and Ryerson Image Arts once. It was at the end of my second interview at YSDN that I was told to stop learning on my own until I get the first few years of a BA out of the way, then try applying again.&lt;/p&gt;

&lt;p&gt;You will meet a lot of different people along the way, many of which will not share your passion. Politely thank them for their opinion, then visualize yourself in the future telling them they were wrong. You’re on the fringe with your scary, self-disciplined ways, and you are going to be going against the grain of many people.&lt;/p&gt;

&lt;h2&gt;3. Get Out There And Mingle&lt;/h2&gt;

&lt;p&gt;A lot of people in my life have just finished university or college and want to get started doing something they love, but how? From my experience handing out resumes and the like won’t get you nearly as far as mingling with the people in your industry.&lt;/p&gt;

&lt;p&gt;I’m lucky that there is a very visible technology community in Toronto and tons of &lt;a href="http://www.facebook.com/group.php?gid=11568591117"&gt;free&lt;/a&gt; or &lt;a href="http://barcamp.org/DemoCampToronto18"&gt;almost free&lt;/a&gt; events all of the time. I met my first employer at a &lt;a href="http://unspace.ca/innovation/pubnite/"&gt;free event&lt;/a&gt;, and I met John and Malgosia at a moving party for the &lt;a href="http://unspace.ca"&gt;company&lt;/a&gt; that organizes that event.&lt;/p&gt;

&lt;p&gt;I always thought the best events were the free ones, my opinion changed this summer though. I attended a &lt;a href="http://rubyfringe.com"&gt;conference&lt;/a&gt; that was worth every dollar. I’ve also attended some &lt;a href="http://railsconf.com"&gt;other&lt;/a&gt; conferences that were not worth their weight in silly clown noses. I will say that for the most part, you get back what you put into these things.&lt;/p&gt;

&lt;p&gt;Take a chance, get out there and meet people! &lt;em&gt;Even if it means spending some money that you might not have.&lt;/em&gt; I’m sure you’ve spent money on &lt;a href="http://heycarsten.com/assets/2008/10/10/my-truck.jpg"&gt;less important&lt;/a&gt; things.&lt;/p&gt;

&lt;h2&gt;4. Don’t Turn Down Any Opportunity&lt;/h2&gt;

&lt;p&gt;My first job in Toronto was at a company called &lt;a href="http://www.globalnerdy.com/2008/09/17/the-return-of-ruby-on-rails-project-night/"&gt;TSOT&lt;/a&gt;, their product was a social network for fraternities, not really something I’m personally interested in. However, for a guy with pretty much zero programming experience at the time it was a rare opportunity. If I brushed it off, I might still be in basement land.&lt;/p&gt;

&lt;h2&gt;5. You Know Nothing&lt;/h2&gt;

&lt;p&gt;Humility is your best friend! You are surrounded by people who know a lot more than you, and if you aren’t then maybe it’s time to smarten up. As soon as you start to feel comfortable, be terrified. You’re not all that great at whatever it is you do, and you have a lot to learn from a lot of people. Embrace it, love it.&lt;/p&gt;

&lt;p&gt;Another part of this is accepting criticism gracefully. It’s only criticism, you don’t have to act on it, but it should always cause you to think twice. If you don’t listen to other peoples’ opinions about your work then you are missing out on a huge amount of opportunity. The twist to this is that you can really learn a lot about someone in the way that they deliver their criticisms to you.&lt;/p&gt;

&lt;h2&gt;6. Don’t Let The Haters Get You Down&lt;/h2&gt;

&lt;p&gt;You are always going to encounter toxic people that simply don’t like you. Maybe they are jealous and feel threatened by you and your kind or maybe they were born without genitalia and are just generally miserable, or maybe you can be a bit of a condescending asshole at times. Whatever the case, being pissed off is not going to help. So &lt;a href="http://twitter.com/heycarsten/statuses/943290529"&gt;bitch&lt;/a&gt; about it on &lt;a href="http://twitter.com"&gt;Twitter&lt;/a&gt; and move on.&lt;/p&gt;

&lt;h2&gt;7. Stay Absolutely Positive&lt;/h2&gt;

&lt;p&gt;You’re doing what you love, after all! And if not, then why not?&lt;/p&gt;
          </content>  <feedburner:origLink>http://heycarsten.com/2008/10/10/seven-ways-to-get-out-of-the-basement</feedburner:origLink></entry>
  <entry xml:base="http://heycarsten.com/">
    <author>
      <name>Carsten Nielsen</name>
    </author>
    <id>tag:heycarsten.com,2008-09-29:65</id>
    <published>2008-09-29T16:38:00Z</published>
    <updated>2008-10-10T02:48:05Z</updated>
    <category term="basic" />
    <category term="left" />
    <category term="ruby" />
    <category term="rubyisms" />
    <category term="syntax goodies" />
    <link href="http://feedproxy.google.com/~r/heycarsten/~3/Q4BIoZWySVA/rubyisms-that-ruby-programmers-should-know" rel="alternate" type="text/html" />
    <title>Rubyisms That Ruby Programmers Should Know</title>
<content type="html">
            &lt;p&gt;There are a few things that I know now and take for granted which used to blow my mind. If only someone took the 10 minutes to explain these concepts to me back when I started programming I would have been in the know so much sooner. Hopefully I can be that someone for you if you are stuck on any of these yourself.&lt;/p&gt;

&lt;h3&gt;The Splat&lt;/h3&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;
def stuff(*args)
  args.inspect
end

stuff 1, 'neck', :blog # =&gt; [1, 'neck', :block]
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Splats are basically like telling your method to take as many arguments as it wants and put them in an array called, in this case, &lt;code&gt;args&lt;/code&gt;. You can name your splat anything you’d like. Splats can also appear along with other arguments in a method definition like this:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;
def say_jobs(person, *tasks)
  puts "#{person} will: #{tasks.join(', ')}."
end

say_jobs 'Carsten', 'clean floor', 'make dinner', 'bake a pie'
# =&gt; 'Carsten will clean floor, make dinner, bake a pie.'
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;You might also see a splat appear backwards in the form of a list assignment like this:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;
malted_battery_acids = ['Coke', 'Pepsi', 'RC Cola']
coke, pepsi, rc_cola = *malted_battery_acids
&lt;/code&gt;
&lt;/pre&gt;

&lt;h3&gt;Array of Words&lt;/h3&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;
%w[cat dog bat hat]      # =&gt; ['cat', 'dog', 'bat', 'hat']
%w[carsten\ nielsen hat] # =&gt; ['carsten nielsen', 'hat']
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;This is a simple macro which creates an array of strings. It is whitespace sensitive, so it treats everything between spaces as a separate word. You can escape spaces to create words with spaces in them but just keep in mind that it can get confusing for others to read when you start doing stuff like that.&lt;/p&gt;

&lt;p&gt;It should also be noted that I chose to use square brackets as start and end delimiters, but you can use curly braces, quotes, bars, most anything you’d like for all the percent-style literals.&lt;/p&gt;

&lt;h3&gt;Alternative String Literals&lt;/h3&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;
%{greetings good sir}  # &amp;lt;-&gt;&amp;lt;-&gt;&amp;lt;-&gt;&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;You can think of these as the heredoc for minimalists. If you use a lowercase &lt;code&gt;q&lt;/code&gt; it behaves like a single quoted string, otherwise you have full interpolation like a double quoted string.&lt;/p&gt;

&lt;h3&gt;Shelling Out&lt;/h3&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;
`which ruby`   # =&gt; '/opt/local/bin/ruby'
%x{which ruby} # =&gt; '/opt/local/bin/ruby'
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Whatever you place between the back-ticks is sent to the shell, the results are returned as a string. There is an alternate style too that behaves the same.&lt;/p&gt;

&lt;h3&gt;The Blarg &lt;em&gt;(Block Argument)&lt;/em&gt;&lt;/h3&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;
def quote(&amp;block)
  "&amp;amp;ldquo;#{block.call}&amp;amp;rdquo;"
end

quote { 'Johnny Walker Black' }
# =&gt; '&amp;amp;ldquo;Johnny Walker Black&amp;amp;rdquo;'
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Blargs are great when you have a method that requires a block. If you call the method without a block it will raise an error at runtime. In my example I reference the block by it’s blarg’s name but you can use &lt;code&gt;yield&lt;/code&gt; too.&lt;/p&gt;
          </content>  <feedburner:origLink>http://heycarsten.com/2008/9/29/rubyisms-that-ruby-programmers-should-know</feedburner:origLink></entry>
  <entry xml:base="http://heycarsten.com/">
    <author>
      <name>Carsten Nielsen</name>
    </author>
    <id>tag:heycarsten.com,2008-06-25:4</id>
    <published>2008-06-25T19:00:00Z</published>
    <updated>2008-10-10T02:47:03Z</updated>
    <category term="haml" />
    <category term="left" />
    <category term="sass" />
    <link href="http://feedproxy.google.com/~r/heycarsten/~3/48boPxQEI90/living-with-haml-and-sass" rel="alternate" type="text/html" />
    <title>Living With Haml &amp; Sass</title>
<content type="html">
            &lt;p&gt;Haml is a pretty awesome templating language for marking up XML documents and hands-down brilliant for marking up XHTML, I think most people who “get it” use Haml whenever they can.  We’ve been using it since day one at LearnHub, it makes my job a lot more enjoyable having yet another elegant tool at my disposal.  And yes, it’s fast!&lt;/p&gt;

&lt;p&gt;So pretty much everyone agrees Haml is fantastic, but what about Haml’s smokin’ hot sister; Sass?  I have been using Sass exclusively on LearnHub since day one too, I find the benefits to be just as high as Haml if not higher, especially when it comes to nested selectors, less typing means less room for error and a document that is compact and easier to read.&lt;/p&gt;

&lt;p&gt;There are not as many people out there using Sass though, and I think that is a shame.  Sass lets you do some pretty nifty things that in turn give you great power.  You can easily scope sets of rules to certain selectors and change them with ease, Sass removes all of the syntactic dirt and mostly all of the repetition from CSS.  Consider the following example:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="css"&gt;
#content {
  margin: 0 8px; }
  #content .block {
    border: 1px solid #ddd; }
    #content .block p {
      font-size: 116%; }
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Not bad, now let’s see it in Sass:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="sass"&gt;
#content
  :margin 0 8px
  .block
    :border 1px solid #ddd
    p
      :font-size 116%
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Sweet jeebas, why wouldn’t you want that?&lt;/p&gt;

&lt;p&gt;Another one of my favorite things about Sass is the ability to declare constants, take the following for example, the ability to spec out all of your typefaces in one spot:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="sass"&gt;
!display = "'lucida grande', 'trebuchet ms'"
!sans = "'helvetica neue', arial, 'dejavu sans'"
!serif = "georgia, times"
!monospace = "monaco, consolas, 'dejavu sans mono'"
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;And the power to do  fun stuff such as:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="sass"&gt;
!gunmetal = #ccc
!steel = !gunmetal + #111
!aluminum = !steel + #111
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Now I personally don’t use evaluations in Sass very much, I find it easier to just declare everything explicitly, but I often use string concatenation in Sass everywhere:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="sass"&gt;
.pillar
  .brick
    :border = "1px solid" !steel
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;In spite of Hampton raising an eyebrow, I break from convention and store my Sass documents in &lt;code&gt;/app/sass&lt;/code&gt; which I then have compile out into &lt;code&gt;/public/stylesheets/compiled&lt;/code&gt; this works better for me as it removes any confusion as to what stylesheets are Sass output and what are hand-coded CSS.&lt;/p&gt;

&lt;p&gt;To do this, simply set the following Sass options during initialization:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;
Sass::Plugin.options[:template_location] = File.join(RAILS_ROOT, 'app/sass')
Sass::Plugin.options[:css_location] = File.join(RAILS_ROOT, 'public/stylesheets/compiled')
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;I tip my hat to Nathan and the other contributors of Haml; it keeps getting better and better in terms of speed and features.  I remember pre version 1.8 speed was a bit of a concern, but after its release the cynics stopped knocking.  With the recent release of version 2 we have seen a slew of improvements and enhancements (better error messages, auto-escaping) as well as yet another speed boost &amp;mdash; LOVE IT!&lt;/p&gt;
          </content>  <feedburner:origLink>http://heycarsten.com/2008/6/25/living-with-haml-and-sass</feedburner:origLink></entry>
  <entry xml:base="http://heycarsten.com/">
    <author>
      <name>Carsten Nielsen</name>
    </author>
    <id>tag:heycarsten.com,2008-06-21:6</id>
    <published>2008-06-21T05:16:00Z</published>
    <updated>2008-10-24T18:59:00Z</updated>
    <category term="extensions" />
    <category term="left" />
    <category term="rails" />
    <category term="ruby" />
    <category term="to_params" />
    <category term="urilize" />
    <link href="http://feedproxy.google.com/~r/heycarsten/~3/ArupDUN_lmg/informative-and-painless-uris" rel="alternate" type="text/html" />
    <title>Informative &amp; Painless URIs</title>
<content type="html">
            &lt;p&gt;There is just something nice about those cute URIs that we have all grown to love, I’m sure you’ve seen them around: &lt;code&gt;http://pork.ham/lists/32-grocery-list&lt;/code&gt;.  Guess what, these are fun and easy to implement, here’s how!&lt;/p&gt;

&lt;p&gt;First we need a method that can convert a normal title or name into something safe for use in a URI, here’s my answer:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;
class ::String

  # Returns a version of self that is safe for inclusion in a URI.
  def urilize
    strip.
    gsub(' ', '-').
    gsub(/[-]+/, '-').
    gsub('&amp;', 'and').
    downcase.
    scan(/[a-z0-9\-]*/).to_s
  end

end
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Users enter the darnedest data, so your &lt;code&gt;urilize&lt;/code&gt; implementation will probably be tweaked over time. Anyways, the above String extension let’s us do stuff like:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;
'My Name Is Mud!'.urilize # =&gt; "my-name-is-mud"
'Awesome  &amp;  Cool Stuff!!!'.urilize # =&gt; "awesome-and-cool-stuff"
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Now we need a seamless way to get this functionality into our models so that they start throwing around all of these cool URIs for free.  My answer to this is a sweet and simple mixin:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;
module Findable

  def to_param
    to_s.blank? ? id.to_s : "#{id}-#{to_s.urilize}"
  end

end
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;In order for our mixin to work we need our ActiveRecord models to have an overloaded &lt;code&gt;to_s&lt;/code&gt; method that returns the title or name of the object.  This is good practice and you should be doing it in any model where it makes sense to do so.&lt;/p&gt;

&lt;p&gt;Anyways we can use our mixin as follows:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;
class Ticket &amp;lt; ActiveRecord::Base

  include Findable

  ...

  def to_s
    title
  end

  ...

end
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Now imagine we have the following ticket in our database:&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;
id: 6
created_by: Captain Obvious
assigned_to: Developer Dude
title: Feature Improvements
body: This massive feature that you implemented in far too little time is imperfect!
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Assuming resourceful routes for Tickets we can do something like:&lt;/p&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;
ticket = Ticket.find(6)
ticket_path(ticket) # =&gt; "/tickets/6-feature-improvements"
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Neat.&lt;/p&gt;
          </content>  <feedburner:origLink>http://heycarsten.com/2008/6/21/informative-and-painless-uris</feedburner:origLink></entry>
  <entry xml:base="http://heycarsten.com/">
    <author>
      <name>Carsten Nielsen</name>
    </author>
    <id>tag:heycarsten.com,2008-06-13:2</id>
    <published>2008-06-13T23:13:00Z</published>
    <updated>2008-10-10T02:46:27Z</updated>
    <category term="hacks" />
    <category term="left" />
    <category term="method name" />
    <category term="ruby" />
    <link href="http://feedproxy.google.com/~r/heycarsten/~3/28rtLCQwTD4/method-name" rel="alternate" type="text/html" />
    <title>Method Name Hack</title>
<content type="html">
            &lt;p&gt;Ruby lets you do some pretty fun stuff, from highly elegant and useful to interesting and hacky.  This is more of a hack than anything but it demonstrates some cool concepts.&lt;/p&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;
module ::Kernel

  private
  # Allows you to get the name of the current method inside that method.
  # Example:
  #
  #   def hello
  #     __method_name__
  #   end
  #
  #   hello # =&gt; "hello"
  def __method_name__
    caller[0].scan(/`(.*)'/).to_s
  end

end
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;Ruby let’s you extend anything and everything, which is pretty powerful.  The two preceding colons in &lt;code&gt;::Kernel&lt;/code&gt; tell Ruby to access the Kernel module in the global object space, if we were already there they would not be necessary but to be safe it’s best to add them.&lt;/p&gt;

&lt;p&gt;Ruby maintains a call stack which is basically an array of strings that look like:&lt;/p&gt;

&lt;pre&gt;
&lt;code&gt;
/Users/carsten/Projects/coolness/cool.rb:12:in `awesome_method'
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;This lets us know the path and file name as well as the line number and method name; neat.  Then we just do a cute little regular expression scan and we can see the name of the method we are inside of.&lt;/p&gt;
          </content>  <feedburner:origLink>http://heycarsten.com/2008/6/13/method-name</feedburner:origLink></entry>
  <entry xml:base="http://heycarsten.com/">
    <author>
      <name>Carsten Nielsen</name>
    </author>
    <id>tag:heycarsten.com,2008-06-12:1</id>
    <published>2008-06-12T01:08:00Z</published>
    <updated>2008-06-16T21:39:30Z</updated>
    <category term="development" />
    <category term="helpers" />
    <category term="rails" />
    <category term="textmate commands" />
    <link href="http://feedproxy.google.com/~r/heycarsten/~3/ag3I7TQsoEQ/go-to-helper-method-textmate-command" rel="alternate" type="text/html" />
    <title>Go To Helper Method: TextMate Command</title>
<content type="html">
            &lt;p&gt;If you&amp;rsquo;re like me you use a lot of view helpers, stored in many different files.  On big projects it&amp;rsquo;s not always easy to remember what helper came from where.  You can use naming schemes and other organizational techniques, but you still have to take a few steps to get to the file and then find the method.  Life is hard.&lt;/p&gt;

&lt;p&gt;Or is it!?  Life is easy when you use my &lt;strong&gt;Go To Helper Method&lt;/strong&gt; command for TextMate!  It does a simple grep of the current project&amp;rsquo;s &lt;code&gt;/app/helpers&lt;/code&gt; directory (and sub-directories) for the method name in question and then opens the file and places you at the appropriate method. This approach works well because helper methods are &lt;em&gt;usually&lt;/em&gt; all in the same namespace.&lt;/p&gt;

&lt;p&gt;For the command to work properly you must have a TextMate Project of your application&amp;rsquo;s root open with at least the &lt;code&gt;/app&lt;/code&gt; directory referenced.  You can then run the command by placing the cursor on (or selecting) the name of a helper method in any Ruby, &lt;a href="http://haml.hamptoncatlin.com"&gt;Haml&lt;/a&gt; or ERb file, then hitting the default key-sequence of &lt;strong&gt;Shift→Cmd→H&lt;/strong&gt;; magic ensues.&lt;/p&gt;

&lt;pre&gt;
&lt;code class="ruby"&gt;
#!/usr/bin/env ruby -w
require File.join(ENV['TM_SUPPORT_PATH'], 'lib/textmate')

PROJECT_DIR = ENV['TM_PROJECT_DIRECTORY']
METHOD_NAME = ENV['TM_CURRENT_WORD'] || ENV['TM_CURRENT_SELECTION']

def blank?(string)
  string.nil? || string.strip.eql?('')
end

def helpers_dir
  File.join(PROJECT_DIR, 'app/helpers/*')
end

def grep_and_go_to!
  method_name = Regexp.escape(METHOD_NAME)
  grep = `grep -rnE "def #{method_name}([\( ]{1}|$)" #{helpers_dir}`
  filepath, line = grep.match(/^.+:[\d]+/).to_s.strip.split(':')
  if filepath &amp;&amp; line
    TextMate.go_to(:file =&gt; filepath, :line =&gt; line)
  else
    puts 'Could not find a matching Helper file'
  end
end

if blank?(PROJECT_DIR)
  puts 'Go To Helper Method only works in a project!'
elsif blank?(METHOD_NAME)
  puts 'Place the cursor over the name of a Helper method'
else
  grep_and_go_to!
end
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;The command works well inside Merb&lt;sup&gt;&lt;a href="#merb_footnote"&gt;1&lt;/a&gt;&lt;/sup&gt; and Rails projects. &lt;em&gt;It probably works with other stuff too if there are Ruby files in &lt;code&gt;/app/helpers&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;Update&lt;/h2&gt;

&lt;p&gt;If you think this is neat check out &lt;a href="http://github.com/haru01/easy-open-tmbundle/tree/master"&gt;EasyOpen&lt;/a&gt; by Eiji Ienaga over on GitHub, it makes my simple command here look like childs play!&lt;/p&gt;

&lt;p class="download_box"&gt;
  &lt;a href="/assets/2008/6/12/goto_helper_method.zip"&gt;Download It Here&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;
&lt;small&gt;1. &lt;em&gt;That&amp;rsquo;s if you&amp;rsquo;ve decided to keep your helpers in /app/helpers.&lt;/em&gt;&lt;/small&gt;&lt;/p&gt;
          </content>  <feedburner:origLink>http://heycarsten.com/2008/6/12/go-to-helper-method-textmate-command</feedburner:origLink></entry>
</feed>
