<?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">
 
 <title>Liah Hansen</title>
 
 <link href="http://liahhansen.com/" />
 <updated>2011-04-28T22:03:35-07:00</updated>
 <id>http://liahhansen.com/</id>
 <author>
   <name>Liah Hansen</name>
 </author>

 
 <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/liahhansen" /><feedburner:info uri="liahhansen" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
   <title>Checking A Column's Datatype in a Rails 3 Migration</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/rA7G5pP_whc/checking-column-datatype-rails-3-migration.html" />
   <updated>2011-04-28T00:00:00-07:00</updated>
   <id>http://liahhansen.com/2011/04/28/checking-column-datatype-rails-3-migration</id>
   <content type="html">&lt;h1&gt;Checking A Column's Datatype in a Rails 3 Migration&lt;/h1&gt;

&lt;p&gt;Today we were temporarily perplexed because Facebook ids were being
saved in MySQL as completely different numbers than we were expecting.
The problem ended up being that the datatype was Int instead of BigInt.&lt;/p&gt;

&lt;p&gt;We wanted to be able to determine the datatype of a column through
ActiveRecord in our migration.  This is how to get that info:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="no"&gt;Widget&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;columns_hash&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;id&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="n"&gt;sql_type&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/rA7G5pP_whc" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2011/04/28/checking-column-datatype-rails-3-migration.html</feedburner:origLink></entry>
 
 <entry>
   <title>Rails Console - Show Error Messages for All Object Attributes</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/jH1DHpBp0PE/rails-console-show-error-messages-for-all-attributes.html" />
   <updated>2011-04-15T00:00:00-07:00</updated>
   <id>http://liahhansen.com/2011/04/15/rails-console-show-error-messages-for-all-attributes</id>
   <content type="html">&lt;h1&gt;Rails Console - Show Error Messages for All Object Attributes&lt;/h1&gt;

&lt;p&gt;To view all of the errors on each of the attributes of your ActiveRecord
object (Rails 3), use Object.errors.full_messages:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;User&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;User id: nil, email: &amp;quot;&amp;quot;, encrypted_password: &amp;quot;&amp;quot;, reset_password_token: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, confirmation_token: nil, confirmed_at: nil, confirmation_sent_at: nil, created_at: nil, updated_at: nil&amp;gt; &lt;/span&gt;
 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;save&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt; 
 &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;full_messages&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;Email can&amp;#39;t be blank&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Password can&amp;#39;t be blank&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/jH1DHpBp0PE" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2011/04/15/rails-console-show-error-messages-for-all-attributes.html</feedburner:origLink></entry>
 
 <entry>
   <title>Testing Model Associations in Rspec (Rails 3)</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/j1KE519zWqY/testing-model-associations-in-rspec.html" />
   <updated>2011-04-14T00:00:00-07:00</updated>
   <id>http://liahhansen.com/2011/04/14/testing-model-associations-in-rspec</id>
   <content type="html">&lt;h1&gt;Testing Model Associations in Rspec (Rails 3)&lt;/h1&gt;

&lt;p&gt;I live with five really awesome housemates.  Five warm bodies tend to
make a mess by the end of the week so we have a chore chart on the
fridge.  I tend to be the one who
badgers everyone else into doing their weekly chore - not my favorite
thing to do...so, I figure it's time to put Rails to work sending
those emails for me.&lt;/p&gt;

&lt;p&gt;I named our fridge chore chart replacement &lt;em&gt;Choretle&lt;/em&gt;.  I'm excited to get it finished so that it can do all the dirty work of emailing
reminders and doling out appropriate praise for a job well done.&lt;/p&gt;

&lt;p&gt;I've got my data model pretty much sorted out at this
point and I just started generating my models.  I decided to do some
googling about testing model associations since it has never been as streamlined as I'd like.  I found a
couple of ways to test associations, some of them better than others.&lt;/p&gt;

&lt;p&gt;The way I've tested associations in the past has gone something like
this:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="no"&gt;Group&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;should respond to users&amp;quot;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Group&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;
    &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;should&lt;/span&gt; &lt;span class="n"&gt;respond_to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:users&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;What I don't like about it is that it is a round-about way of testing
for an association.  It tests a side effect of the association, not that
the association exists.&lt;/p&gt;

&lt;p&gt;The next solution I found is built  into ActiveRecord::Reflection::AssociationReflection, so no need to install extra gems:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;  &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Group&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;reflect_on_association&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:users&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;ActiveRecord::Reflection::ThroughReflection:0x00000100d65208 @macro=:has_many, @name=:users, @options={:through=&amp;gt;:affiliations, :extend=&amp;gt;[]}, @active_record=Group(id: integer, name: string, creator: integer, created_at: datetime, updated_at: datetime), @collection=true&amp;gt; &lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;macro&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ss"&gt;:has_many&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;The &lt;code&gt;macro&lt;/code&gt; method makes it fairly easy to write an
association test:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="no"&gt;Group&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;should have many users&amp;quot;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Group&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;reflect_on_association&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:users&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;macro&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;should&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="ss"&gt;:has_many&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;It is still kinda ugly don't you think?  Definitely not an elegant way
to indicate the relationship.  Luckily, I found a couple of
recommendations for gems that make for more descriptive syntax: remarkable and shoulda.  Both gems have similar syntax:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="c1"&gt;#both remarkable and shoulda use this syntax&lt;/span&gt;
    &lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="no"&gt;Group&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
      &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;should&lt;/span&gt; &lt;span class="n"&gt;belong_to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:supergroup&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;should&lt;/span&gt; &lt;span class="n"&gt;have_many&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:users&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Remarkable seems cool, but from what I could tell, it isn't well maintained.  The last commit is from about a year ago on the &lt;a href="https://github.com/carlosbrando/remarkable"&gt;carlosbrando fork&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I decided to use Shoulda for my tests.  It's easy to get working - just
add &lt;code&gt;gem 'shoulda-matchers'&lt;/code&gt; to the Gemfile.&lt;/p&gt;

&lt;p&gt;Here is my (short and symantically relevent) model association test:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;  &lt;span class="n"&gt;describe&lt;/span&gt; &lt;span class="no"&gt;Group&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;it&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;should&lt;/span&gt; &lt;span class="n"&gt;have_many&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:users&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;In my research, I encountered some debate about whether testing
associations is
worthwhile in the first place.  Some people argue that it is testing Rails instead of your own code.  I'd argue that testing
associations isn't testing Rails.  It is testing that your code is
hooked up the way you want it.  Testing associations also gets me into
the
TDD frame of mind as soon as I start a project.  Plus, when Shoulda makes it so easy,
I don't have any excuses not to test associations.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/j1KE519zWqY" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2011/04/14/testing-model-associations-in-rspec.html</feedburner:origLink></entry>
 
 <entry>
   <title>NERDTree for Macvim - Everything I've Learned So Far</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/hoNP9Gzjd6w/vim-nerdtree-adding-deleting-and-moving-files.html" />
   <updated>2011-04-07T00:00:00-07:00</updated>
   <id>http://liahhansen.com/2011/04/07/vim-nerdtree-adding-deleting-and-moving-files</id>
   <content type="html">&lt;h1&gt;NERDTree for Macvim - Everything I've Learned So Far&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;To toggle the vertical NERDTree window on and off, use &lt;code&gt;:NERDTreeToggle&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;To open a tab and move into it use &lt;code&gt;j&lt;/code&gt; or &lt;code&gt;k&lt;/code&gt; to navigate the file you want to open, then hit &lt;code&gt;t&lt;/code&gt; from the NERDTree window&lt;/li&gt;
&lt;li&gt;To open a tab but stay in the current tab, use  &lt;code&gt;j&lt;/code&gt; or &lt;code&gt;k&lt;/code&gt; to navigate the file you want to open, then hit &lt;code&gt;T&lt;/code&gt; from the NERDTree Window&lt;/li&gt;
&lt;li&gt;To move a file in the NERDTree window, use  &lt;code&gt;m&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;To add a file in the NERDTree window, use  &lt;code&gt;a&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;To navigate to the next tab, use &lt;code&gt;gt&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;To navigate to the previous tab, use &lt;code&gt;gT&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;All window commands start with &lt;code&gt;ctrl w&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;To move back to the NERDTree window from another split window in the current tab, use &lt;code&gt;ctrl ww&lt;/code&gt; or &lt;code&gt;ctrl wh&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;To move between windows in general, &lt;code&gt;ctrl wh&lt;/code&gt; takes you left, &lt;code&gt;ctrl wl&lt;/code&gt; takes you right, &lt;code&gt;ctrl wj&lt;/code&gt; takes you down and &lt;code&gt;ctrl wk&lt;/code&gt; takes you up.&lt;/li&gt;
&lt;li&gt;To quit a window use &lt;code&gt;ctrl wq&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/hoNP9Gzjd6w" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2011/04/07/vim-nerdtree-adding-deleting-and-moving-files.html</feedburner:origLink></entry>
 
 <entry>
   <title>Scheme - Generalizing Functions</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/tXrl5jqKEO4/scheme-lecture-3-notes.html" />
   <updated>2011-04-03T00:00:00-07:00</updated>
   <id>http://liahhansen.com/2011/04/03/scheme-lecture-3-notes</id>
   <content type="html">&lt;h1&gt;Scheme - Generalizing Functions&lt;/h1&gt;

&lt;p&gt;These are notes I took while watching the third lecture of &lt;a href="http://webcast.berkeley.edu/course_details_new.php?seriesid=2010-B-26275&amp;amp;semesterid=2010-B"&gt;Brian Harvey's 61A CS Class&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Topic: Generalizing Functions&lt;/p&gt;

&lt;p&gt;The code below can also be found &lt;a href="http://inst.eecs.berkeley.edu/~cs61a/sp11/lectures/1.3/"&gt;on the Berkeley website&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;First we saw how to generalize our sumsquare function so that it can also work for sumcube:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="scheme"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sumsquare&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;&amp;gt; &lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="mi"&gt;0&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+ &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;* &lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sumsquare&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+ &lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sumcube&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;&amp;gt; &lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="mi"&gt;0&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+ &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;* &lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sumcube&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+ &lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sum&lt;/span&gt; &lt;span class="nv"&gt;fn&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;&amp;gt; &lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="mi"&gt;0&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+ &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;fn&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sum&lt;/span&gt; &lt;span class="nv"&gt;fn&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+ &lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;square&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;* &lt;/span&gt;&lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cube&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;* &lt;/span&gt;&lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Next we generalized functions that perform specific tasks such as returning a list of the even numbers from a list of both even and odd numbers:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="scheme"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;evens&lt;/span&gt; &lt;span class="nv"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;cond &lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nf"&gt;empty?&lt;/span&gt; &lt;span class="nv"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nb"&gt;= &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;remainder &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt; &lt;span class="nv"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
         &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;se&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt; &lt;span class="nv"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;evens&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;bf&lt;/span&gt; &lt;span class="nv"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;else &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;evens&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;bf&lt;/span&gt; &lt;span class="nv"&gt;nums&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt; &lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This function returns a list of words that have an 'e':&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="scheme"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ewords&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;cond &lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nf"&gt;empty?&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nf"&gt;member?&lt;/span&gt; &lt;span class="ss"&gt;&amp;#39;e&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
         &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;se&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ewords&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;bf&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;else &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ewords&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;bf&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt; &lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This function returns the pronouns of a sentence:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="scheme"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;pronouns&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;cond &lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nf"&gt;empty?&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
        &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nf"&gt;member?&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;I&lt;/span&gt; &lt;span class="nv"&gt;me&lt;/span&gt; &lt;span class="nv"&gt;you&lt;/span&gt; &lt;span class="nv"&gt;he&lt;/span&gt; &lt;span class="nv"&gt;she&lt;/span&gt; &lt;span class="nv"&gt;it&lt;/span&gt; &lt;span class="nv"&gt;him&lt;/span&gt; &lt;span class="nv"&gt;her&lt;/span&gt; &lt;span class="nv"&gt;we&lt;/span&gt; &lt;span class="nv"&gt;us&lt;/span&gt; &lt;span class="nv"&gt;they&lt;/span&gt; &lt;span class="nv"&gt;them&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
         &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;se&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;pronouns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;bf&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt; &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;else &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;pronouns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;bf&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt; &lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This function generalizes the above functions so that we can use just one function to perform the same behavior as the above three functions:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="scheme"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt; &lt;span class="nv"&gt;pred&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cond&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nf"&gt;empty?&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
       &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nf"&gt;pred&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;))(&lt;/span&gt;&lt;span class="nf"&gt;se&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt; &lt;span class="nv"&gt;pred&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;bf&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;))))&lt;/span&gt;
       &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;else &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt; &lt;span class="nv"&gt;pred&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;bf&lt;/span&gt; &lt;span class="nv"&gt;sent&lt;/span&gt;&lt;span class="p"&gt;)))))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;The most important word in computer science is &lt;em&gt;Abstraction&lt;/em&gt;.  The second and third most important words are &lt;em&gt;Domain&lt;/em&gt; and &lt;em&gt;Range&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Domain: What kind of arguments does it take&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: domain of &lt;em&gt;=&lt;/em&gt; is numbers whereas domain of &lt;em&gt;equal?&lt;/em&gt; is anything&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Range: Set of possible values a function can return&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Example: predicate is a function whose range is true or false&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Higher Order Function: A function that has a function as an argument and/or a function as a return value&lt;/p&gt;

&lt;p&gt;First Class Data Type:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;can be the value of a variable&lt;/li&gt;
&lt;li&gt;can be an argument to a procedure&lt;/li&gt;
&lt;li&gt;can be a value returned by a procedure&lt;/li&gt;
&lt;li&gt;can be an element of a data aggregate&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Data aggregate is like an array or a list, etc.&lt;/p&gt;

&lt;p&gt;The way we define functions...like this:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="scheme"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="nv"&gt;square&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;* &lt;/span&gt;&lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;is actually shorthand for this:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="scheme"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="nv"&gt;square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;lambda &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;* &lt;/span&gt;&lt;span class="nv"&gt;x&lt;/span&gt; &lt;span class="nv"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;The lambda is added in by the Scheme interpreter&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/tXrl5jqKEO4" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2011/04/03/scheme-lecture-3-notes.html</feedburner:origLink></entry>
 
 <entry>
   <title>Unix - find /path_to_search -print | grep filename</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/_Ye7VXE2iIs/ls-full-path-to-file-is-actually-find-print.html" />
   <updated>2011-03-30T00:00:00-07:00</updated>
   <id>http://liahhansen.com/2011/03/30/ls-full-path-to-file-is-actually-find-print</id>
   <content type="html">&lt;h1&gt;Unix - find /path_to_search -print | grep filename&lt;/h1&gt;

&lt;p&gt;I was using &lt;code&gt;ls -R | grep filename&lt;/code&gt; trying to find a particular file deep within the font bowls of Tex.  It found the file just fine, but then I needed to know where the file lives.  Here is the magic code: &lt;code&gt;$ find /path_to_search -print | grep filename&lt;/code&gt;&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/_Ye7VXE2iIs" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2011/03/30/ls-full-path-to-file-is-actually-find-print.html</feedburner:origLink></entry>
 
 <entry>
   <title>Scheme - Sum of Biggest Squares, Lambda Calculus (Noisebridge Notes)</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/GtSdIZCqWio/noisebridge-scheme-notes.html" />
   <updated>2011-03-27T00:00:00-07:00</updated>
   <id>http://liahhansen.com/2011/03/27/noisebridge-scheme-notes</id>
   <content type="html">&lt;h1&gt;Scheme - Sum of Biggest Squares, Lambda Calculus (Noisebridge Notes)&lt;/h1&gt;

&lt;p&gt;I just got home from the &lt;a href="https://www.noisebridge.net/wiki/Schemers"&gt;Noisebridge Schemers&lt;/a&gt; meetup.  We started off talking about problem 1.2 (1985 version) / 1.3 (1996 version).  Here's the problem:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Here is our first implementation:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="scheme"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;define &lt;/span&gt;&lt;span class="nv"&gt;ssq2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;a,&lt;/span&gt; &lt;span class="nv"&gt;b,&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;and &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;a&amp;lt;=b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;a&amp;lt;=c&lt;/span&gt;&lt;span class="p"&gt;))(&lt;/span&gt;&lt;span class="nf"&gt;sum_of_squares&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;and &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;b&amp;lt;=a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;b&amp;lt;=c&lt;/span&gt;&lt;span class="p"&gt;))(&lt;/span&gt;&lt;span class="nf"&gt;sum_of_squares&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;and &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;c&amp;lt;=a&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;c&amp;lt;=b&lt;/span&gt;&lt;span class="p"&gt;))(&lt;/span&gt;&lt;span class="nf"&gt;sum_of_squares&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;We talked about how writing this function in scheme involves thinking in a different way than if we were to write it in Ruby.  In Ruby we might sort the arguments using a sort method, then eliminate the smallest one.  Ruby gives us sort and min/max methods for free.  In Scheme it isn't quite so easy.  In Scheme we think about the problem more in terms of a tree whereas in Ruby we manipulate our data in memory using methods.  To illustrate this point, we considered the following code which is how we might think about the problem in a Rubyish way.  It assumes that there is a sort method that takes a greater than or less than symbol to determine whether to sort ascending or descending.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="scheme"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;ssq2&lt;/span&gt; &lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+ &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;* &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;list &lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;list &lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
      &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;* &lt;/span&gt;&lt;span class="nv"&gt;car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cdr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;list &lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
         &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;cdr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;list &lt;/span&gt;&lt;span class="nv"&gt;a&lt;/span&gt; &lt;span class="nv"&gt;b&lt;/span&gt; &lt;span class="nv"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)))))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Here is my implementation in Ruby using a Scheme-like design.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;sum_square_two_biggest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;
    &lt;span class="n"&gt;sum_of_squares&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;
  &lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;=&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;
    &lt;span class="n"&gt;sum_of_squares&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="n"&gt;sum_of_squares&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt; 
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This is an asci art tree that demonstrates how a Schemer might think about the problem.  The left branches are the result of the node being true.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;                &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;
              &lt;span class="o"&gt;/&lt;/span&gt;      &lt;span class="p"&gt;\&lt;/span&gt;
            &lt;span class="o"&gt;/&lt;/span&gt;           &lt;span class="p"&gt;\&lt;/span&gt;
          &lt;span class="o"&gt;|&lt;/span&gt;                &lt;span class="o"&gt;|&lt;/span&gt;   
        &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;                  &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;     
      &lt;span class="o"&gt;|&lt;/span&gt;     &lt;span class="o"&gt;|&lt;/span&gt;              &lt;span class="o"&gt;|&lt;/span&gt;       &lt;span class="o"&gt;|&lt;/span&gt;
      &lt;span class="o"&gt;|&lt;/span&gt;     &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;            &lt;span class="o"&gt;|&lt;/span&gt;       &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;
      &lt;span class="o"&gt;|&lt;/span&gt;     &lt;span class="o"&gt;|&lt;/span&gt;    &lt;span class="p"&gt;\&lt;/span&gt;         &lt;span class="o"&gt;|&lt;/span&gt;     &lt;span class="o"&gt;|&lt;/span&gt;      &lt;span class="o"&gt;|&lt;/span&gt;      
   &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;   &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;   &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;  &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;   &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;   &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;   
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;We talked about functional programing and how using &lt;code&gt;set!&lt;/code&gt; breaks functional programming. Don't use &lt;code&gt;set!&lt;/code&gt; if you want to use applicative evaluation as it forces evaluation immediately.  On the other hand, using &lt;code&gt;define&lt;/code&gt; expands into a lambda expression and does not break functional programming rules.&lt;/p&gt;

&lt;p&gt;Lambda example:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="scheme"&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nf"&gt;lambda&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;+ &lt;/span&gt;&lt;span class="nv"&gt;n&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="mi"&gt;41&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;=&amp;gt; &lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Lambda calculus example:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;λ&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;

&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;λ&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="err"&gt;λ&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;yy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;λ&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;yy&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;λ&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;yy&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="err"&gt;λ&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;λ&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="err"&gt;λ&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;λ&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Book recommendation for lambda calculus: algorithmics by david harel&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/GtSdIZCqWio" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2011/03/27/noisebridge-scheme-notes.html</feedburner:origLink></entry>
 
 <entry>
   <title>Scheme - Functional Programming, Applicative Order, Normal Order</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/VALSSY5MZMg/sicp-functional-programming-applicative-order-normal-order.html" />
   <updated>2011-03-20T00:00:00-07:00</updated>
   <id>http://liahhansen.com/2011/03/20/sicp-functional-programming-applicative-order-normal-order</id>
   <content type="html">&lt;h1&gt;Scheme - Functional Programming, Applicative Order, Normal Order&lt;/h1&gt;

&lt;p&gt;These are notes I took while watching the first lecture of &lt;a href="http://webcast.berkeley.edu/course_details_new.php?seriesid=2010-B-26275&amp;amp;semesterid=2010-B"&gt;Brian Harvey's 61A CS Class&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Functional programming:&lt;/strong&gt;
Output will always be the same if the input is the same - this is helpful in ensuring consistency when we run the same program on different processors (parallel processing)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Applicative order evaluation:&lt;/strong&gt;
All the arguments to Scheme procedures are evaluated when the procedure is applied
in other words, arguments are evaluated before procedures&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Normal order evaluation:&lt;/strong&gt;
Evaluation of procedure arguments is delayed until the actual argument values are needed. Delaying evaluation of procedure arguments until the last possible moment (e.g., until they are required by a primitive operation) is called lazy evaluation.&lt;/p&gt;

&lt;p&gt;You are only assured of getting the right answer with both applicative and normal order evaluation when using functional programming.  The following example illustrates how if we don't follow the rules of functional programming (same output for same input), we may get different results for normal vs applicative evaluation.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;zero&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Applicative&lt;/strong&gt;: will always give zero because the argument is evaluated before the procedure is applied:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="n"&gt;zero&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Normal&lt;/strong&gt;: will give varying answers because the entire 10.rand expression is substituted for each of the x’s in the procedure:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="n"&gt;zero&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;In this case by using rand we are breaking the rules of functional programming.   rand is not a function since a function by definition gives the same outputs for the same inputs.  Since it isn’t a function and we aren’t doing functional programming, the order in which things happen matters.&lt;/p&gt;

&lt;p&gt;Moral of the story: if you are doing functional programming, order doesn’t matter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Efficiency can also be different for applicative vs. normal&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Efficiency difference using the square function:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;applicative:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="n"&gt;square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;2+3 is evaluated once&lt;/p&gt;

&lt;p&gt;normal:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="n"&gt;square&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;2+3 is evaluated four times&lt;/p&gt;

&lt;p&gt;There is a way to do things so that normal order comes out to be more efficient, but in this case  applicative was more efficient.  In any case, the point is that you need to think about the order in which operations are performed.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/VALSSY5MZMg" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2011/03/20/sicp-functional-programming-applicative-order-normal-order.html</feedburner:origLink></entry>
 
 <entry>
   <title>Bundle Config &amp; Bundle Open</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/rOewSdCcEB4/bundle-config-and-bundle-open.html" />
   <updated>2011-02-25T00:00:00-08:00</updated>
   <id>http://liahhansen.com/2011/02/25/bundle-config-and-bundle-open</id>
   <content type="html">&lt;h1&gt;Bundle Config &amp;amp; Bundle Open&lt;/h1&gt;

&lt;p&gt;I wanted to be able to open up gems easily from the command line.  I tried&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt; 
bundle open unicorn 
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;and got the following error:&lt;/p&gt;

&lt;p&gt;To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR&lt;/p&gt;

&lt;p&gt;To get rid of this error I added the following to .profile:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt; 
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;BUNDLER_EDITOR&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;mate
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This causes TextMate to open the gem of choice when I call:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt; 
bundle open unicorn 
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/rOewSdCcEB4" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2011/02/25/bundle-config-and-bundle-open.html</feedburner:origLink></entry>
 
 <entry>
   <title>Escaping and Unescaping in HAML</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/9B8clS85_mc/escaping-and-unescaping-in-haml.html" />
   <updated>2011-02-04T00:00:00-08:00</updated>
   <id>http://liahhansen.com/2011/02/04/escaping-and-unescaping-in-haml</id>
   <content type="html">&lt;h1&gt;Escaping and Unescaping in HAML&lt;/h1&gt;

&lt;p&gt;To turn escaped HTML into HAML, use &lt;code&gt;!=&lt;/code&gt; instead of just &lt;code&gt;=&lt;/code&gt;
To escape unescaped HTML, use &lt;code&gt;&amp;amp;=&lt;/code&gt; instead of just &lt;code&gt;=&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&amp;gt; Haml::Engine.new&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;!= &amp;quot;&amp;lt;p&amp;gt; Hello World&amp;lt;/p&amp;gt;&amp;quot;&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;.render&amp;lt;br&amp;gt;
&lt;span class="o"&gt;=&lt;/span&gt;&amp;gt; &lt;span class="s2"&gt;&amp;quot;&amp;lt;p&amp;gt; Hello World&amp;lt;/p&amp;gt;\n&amp;quot;&lt;/span&gt; &amp;lt;br&amp;gt;
&amp;gt; Haml::Engine.new&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;%p Hello World&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;.render&amp;lt;br&amp;gt;
&lt;span class="o"&gt;=&lt;/span&gt;&amp;gt; &lt;span class="s2"&gt;&amp;quot;&amp;lt;p&amp;gt;Hello World&amp;lt;/p&amp;gt;\n&amp;quot;&lt;/span&gt; &amp;lt;br&amp;gt;
&amp;gt; Haml::Engine.new&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;= &amp;quot;&amp;lt;p&amp;gt; Hello World&amp;lt;/p&amp;gt;&amp;quot;&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;.render&amp;lt;br&amp;gt;
&lt;span class="o"&gt;=&lt;/span&gt;&amp;gt; &lt;span class="s2"&gt;&amp;quot;&amp;lt;p&amp;gt; Hello World&amp;lt;/p&amp;gt;\n&amp;quot;&lt;/span&gt; &amp;lt;br&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Resources:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#unescaping_html"&gt;Unescaping HTML&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#escaping_html"&gt;Escaping HTML&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/9B8clS85_mc" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2011/02/04/escaping-and-unescaping-in-haml.html</feedburner:origLink></entry>
 
 <entry>
   <title>redirect_to vs. render - Rails</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/zn1f-HKIx4w/redirect_to-vs-render.html" />
   <updated>2011-02-02T00:00:00-08:00</updated>
   <id>http://liahhansen.com/2011/02/02/redirect_to-vs-render</id>
   <content type="html">&lt;h1&gt;redirect_to vs. render - Rails&lt;/h1&gt;

&lt;h2&gt;redirect_to:&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;redirect_to causes the browser to receive a 302.&lt;/li&gt;
&lt;li&gt;The browser makes a brand new request and you will need to supply the browser with the information it needs to make the request such as the object attributes.&lt;/li&gt;
&lt;li&gt;Any existing variables will be lost.&lt;/li&gt;
&lt;li&gt;redirect_to is the right choice when you are posting a completely filled out form with valid data.&lt;/li&gt;
&lt;/ul&gt;


&lt;br /&gt;


&lt;h2&gt;render:&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;render causes the browser to return a 200.&lt;/li&gt;
&lt;li&gt;The browser does not make a new request and instead just renders the page you specify without sending any information to it.&lt;/li&gt;
&lt;li&gt;The code in the rendered action will not be executed, it simply returns the view&lt;/li&gt;
&lt;li&gt;render is the right choice when a form was incorrectly filled out and you want to display errors on the page you were just on as well as saving state of all the data that had already been entered into the form.&lt;/li&gt;
&lt;/ul&gt;


&lt;br /&gt;


&lt;p&gt;A link that helped me:&lt;br /&gt;
&lt;a href="http://www.helloworlder.com/?p=6"&gt;http://www.helloworlder.com/?p=6&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/zn1f-HKIx4w" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2011/02/02/redirect_to-vs-render.html</feedburner:origLink></entry>
 
 <entry>
   <title>Remove Files Older Than a Particular Date From a Directory in Unix</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/0Gx1BqGTHVs/remove-files-older-than-a-particular-date-from-a-directory-in-unix.html" />
   <updated>2010-12-15T00:00:00-08:00</updated>
   <id>http://liahhansen.com/2010/12/15/remove-files-older-than-a-particular-date-from-a-directory-in-unix</id>
   <content type="html">&lt;h1&gt;Remove Files Older Than a Particular Date From a Directory in Unix&lt;/h1&gt;

&lt;p&gt;I have a folder filled with hundreds of images.  Most of the images were first added to the folder on May 19th.  The folder I'm moving them to already has all the images that were added on May 19th, so to save time, I don't want to move the May 19th images. I made a back up of my images folder that and am using the below commands within it. I only want to keep images added after May 19th in the folder so that I can zip them up and move them to another server.  I'm using a dummy folder I made locally to test this out.  Here are the unix commands I will use:&lt;/p&gt;

&lt;br /&gt;&lt;br /&gt;




&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="o"&gt;[&lt;/span&gt;Liah-Hansens-MacBook-Pro:~/test&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;ls -al
total 0
drwxr-xr-x   6 liahhansen  staff   204 Dec 15 15:01 ./
drwxr-xr-x+ 75 liahhansen  staff  2550 Dec 14 19:18 ../
-rw-r--r--   1 liahhansen  staff     0 Dec 15 13:58 goodbye
drwxr-xr-x   2 liahhansen  staff    68 Dec 14 19:30 happy/
-rw-r--r--   1 liahhansen  staff     0 Dec 15 13:58 hello
-rw-r--r--   1 liahhansen  staff     0 May 24  2010 timefilealittleolder
&lt;span class="o"&gt;[&lt;/span&gt;Liah-Hansens-MacBook-Pro:~/test&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;touch -am 05192010 timefile

&lt;span class="o"&gt;[&lt;/span&gt;Liah-Hansens-MacBook-Pro:~/xargs_test&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;ls -al
total 0
drwxr-xr-x   7 liahhansen  staff   238 Dec 15 15:11 ./
drwxr-xr-x+ 75 liahhansen  staff  2550 Dec 14 19:18 ../
-rw-r--r--   1 liahhansen  staff     0 Dec 15 13:58 goodbye
drwxr-xr-x   2 liahhansen  staff    68 Dec 14 19:30 happy/
-rw-r--r--   1 liahhansen  staff     0 Dec 15 13:58 hello
-rw-r--r--   1 liahhansen  staff     0 May 19  2010 timefile
-rw-r--r--   1 liahhansen  staff     0 May 24  2010 timefilealittleolder
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;The important part:&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="o"&gt;[&lt;/span&gt;Liah-Hansens-MacBook-Pro:~/test&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;find . -mtime +208 -type f | xargs rm
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Now timefile is gone.  Yay!&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&lt;span class="o"&gt;[&lt;/span&gt;Liah-Hansens-MacBook-Pro:~/xargs_test&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;ls -al
total 0
drwxr-xr-x   6 liahhansen  staff   204 Dec 15 15:11 ./
drwxr-xr-x+ 75 liahhansen  staff  2550 Dec 14 19:18 ../
-rw-r--r--   1 liahhansen  staff     0 Dec 15 13:58 goodbye
drwxr-xr-x   2 liahhansen  staff    68 Dec 14 19:30 happy/
-rw-r--r--   1 liahhansen  staff     0 Dec 15 13:58 hello
-rw-r--r--   1 liahhansen  staff     0 May 24  2010 timefilealittleolder
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Yay!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When I performed these commands on the real files, I ran into a problem where many of the file names had whitespace in them.  This caused rm to fail and I still had many files left in the folder from May 19th.  Here is the command that got rid of them once and for all:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt; 
find . -mtime +208 -type f | xargs -I&lt;span class="o"&gt;{}&lt;/span&gt; rm &lt;span class="s1"&gt;&amp;#39;{}&amp;#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Checking just to make sure:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt; 
ls -al |grep &lt;span class="s2"&gt;&amp;quot;May 19&amp;quot;&lt;/span&gt; | wc -l
0
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Golden!&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/0Gx1BqGTHVs" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2010/12/15/remove-files-older-than-a-particular-date-from-a-directory-in-unix.html</feedburner:origLink></entry>
 
 <entry>
   <title>First Program in C</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/UncX9AA5EHA/first-program-in-c.html" />
   <updated>2010-10-04T00:00:00-07:00</updated>
   <id>http://liahhansen.com/2010/10/04/first-program-in-c</id>
   <content type="html">&lt;h1&gt;First Program in C&lt;/h1&gt;

&lt;p&gt;Now that I've got Ruby and Rails fairly well learned and practiced, I decided it was time to start working towards learning some lower level languages.  Here is my first baby step towards learning C:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;touch foo.c
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




&lt;br /&gt;




&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;mate foo.c&lt;span class="sb"&gt;`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;In foo.c I wrote (with the help of my roommate Sean):&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="c"&gt;&lt;span class="cp"&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;Hello World!!!!!!&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;%d&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Next, I compiled my program:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;gcc foo.c
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This created a file called a.out&lt;/p&gt;

&lt;p&gt;Next I ran a.out&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;./a.out
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;And it out put:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;Hello World!!!!!!
0
1
2
3
4
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Sean also taught me how to define the name of the out file:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;gcc -o foo foo.c
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This let me do the following to execute my program:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;./foo
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/UncX9AA5EHA" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2010/10/04/first-program-in-c.html</feedburner:origLink></entry>
 
 <entry>
   <title>Open Government at GoGaRoCo</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/J2Nzrj-P0sg/open-government-at-gogaruco.html" />
   <updated>2010-09-22T00:00:00-07:00</updated>
   <id>http://liahhansen.com/2010/09/22/open-government-at-gogaruco</id>
   <content type="html">&lt;h1&gt;Open Government at GoGaRoCo&lt;/h1&gt;

&lt;p&gt;Eric Mill gave an inspiring talk at Golden Gate Ruby Conference. Below are my notes about it.&lt;/p&gt;

&lt;p&gt;Innovative websites written in Rails and based off of open government data:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;http://datasf.org/showcase/&lt;/li&gt;
&lt;li&gt;http://www.nyc.gov/html/datamine/html/home/home.shtml&lt;/li&gt;
&lt;li&gt;http://data.dc.gov/&lt;/li&gt;
&lt;li&gt;http://www.appsfordemocracy.org/&lt;/li&gt;
&lt;li&gt;http://www.data.gov/&lt;/li&gt;
&lt;li&gt;http://flyontime.us/&lt;/li&gt;
&lt;li&gt;http://usaspending.gov/&lt;/li&gt;
&lt;li&gt;http://sunlightfoundation.com/clearspending/&lt;/li&gt;
&lt;li&gt;http://www.thomas.gov/&lt;/li&gt;
&lt;li&gt;http://www.govtrack.us/ -- scrapes thomas&lt;/li&gt;
&lt;li&gt;http://www.opencongress.org/ -- built off of govtrack.us, rails app

&lt;ul&gt;
&lt;li&gt;inspired congress to publish votes in xml&lt;/li&gt;
&lt;li&gt;senate also puts out info in xml&lt;/li&gt;
&lt;li&gt;no where near all 50 states give out info&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;sunlight is trying to make state apis the norm

&lt;ul&gt;
&lt;li&gt;mongo db is necessary for it - like some states have only one house, not two&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Federal Register - one of the more important publications of the government&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;rulemaking&lt;/li&gt;
&lt;li&gt;public notices&lt;/li&gt;
&lt;li&gt;chances to comment&lt;/li&gt;
&lt;li&gt;published by the office of the public register&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;http://www.govpulse.us/ was one result of a contest - open source rails app on github, EC2&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it shows what is going on in your area&lt;/li&gt;
&lt;li&gt;government contacted them and contracted the develpers&lt;/li&gt;
&lt;li&gt;ditched some red tape&lt;/li&gt;
&lt;li&gt;pushedthem to take risks&lt;/li&gt;
&lt;li&gt;buy-in from the top of the agency&lt;/li&gt;
&lt;li&gt;made something happen in 3 months...much faster than most gov projects&lt;/li&gt;
&lt;li&gt;they cut their hours by 40% at regular jobs&lt;/li&gt;
&lt;li&gt;result of their work: http://www.federalregister.gov/&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Gov is seeing devs as their customers&lt;/p&gt;

&lt;p&gt;America&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;first country to have a freedom of information act&lt;/li&gt;
&lt;li&gt;all govs info is in the public domain&lt;/li&gt;
&lt;li&gt;we have the freedom to set amazing examples - what we do matters - talk to other people&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;2010 census - machine readable, but have to get through 300 pages of pdf instructions - people have written ruby libraries around the data.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/J2Nzrj-P0sg" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2010/09/22/open-government-at-gogaruco.html</feedburner:origLink></entry>
 
 <entry>
   <title>Interesting Questions Students Asked Me</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/Y4sLl7civf4/interesting-questions-students-asked-me-about.html" />
   <updated>2010-09-22T00:00:00-07:00</updated>
   <id>http://liahhansen.com/2010/09/22/interesting-questions-students-asked-me-about</id>
   <content type="html">&lt;h1&gt;Interesting Questions Students Asked Me&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;How Ruby language is structured...Kernal is mixed into Object.  What impact does that have (sleep, method_missing, puts)?  What about Enumerable and the classes it is mixed into...they all have '#each' but how does it work that the methods defined in Enumerable can work for all the different classes?&lt;/li&gt;
&lt;li&gt;Threads in Ruby&lt;/li&gt;
&lt;li&gt;Scaling in Ruby&lt;/li&gt;
&lt;li&gt;DSLs and metaprogramming&lt;/li&gt;
&lt;li&gt;Connection to the database...how is this done internally...does it have to do with IO&lt;/li&gt;
&lt;li&gt;IO&lt;/li&gt;
&lt;li&gt;Procs &amp;amp; Lambdas...what are some real world applications of them.&lt;/li&gt;
&lt;li&gt;what happens when two file objects are created with the same file and try to update the file at the same time&lt;/li&gt;
&lt;li&gt;VMs - is Ruby 1.8.6 the 'main' Ruby...are JRuby, Groovy and other specialized VMs using 'main' Ruby and altering it...or are they rewriting Ruby in a different language...what does virtual machine even really mean in this context...&lt;/li&gt;
&lt;li&gt;regular expressions&lt;/li&gt;
&lt;li&gt;duck typing vs dynamically typed&lt;/li&gt;
&lt;/ul&gt;

&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/Y4sLl7civf4" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2010/09/22/interesting-questions-students-asked-me-about.html</feedburner:origLink></entry>
 
 <entry>
   <title>Voicenotes - My First Twilio App</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/Xxp8ZNhs3ig/voicenotes-my-first-twilio-app.html" />
   <updated>2010-07-25T00:00:00-07:00</updated>
   <id>http://liahhansen.com/2010/07/25/voicenotes-my-first-twilio-app</id>
   <content type="html">&lt;h1&gt;Voicenotes - My First Twilio App&lt;/h1&gt;

&lt;p&gt;Sometimes I wonder about my sanity when I voluntarily spend a sunny Saturday in a basement writing code. Yesterday was one of those days at the Social App Workshop held at Heroku's new headquarters.  The morning was an action packed string of talks from engineers at Twitter, Twilio, Facebook, Apigee and Heroku.  I was really impressed with Jeff's talk about Twilio and thought I'd try making an app with it's api.&lt;/p&gt;

&lt;p&gt;The results of my efforts are here: &lt;a href="http://voicenotes.heroku.com/voice_to_text"&gt;http://voicenotes.heroku.com/voice_to_text&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My goal was to write an app that you could call, record a message, and the message would be transcribed and put on a webpage. The transcribe feature is pretty inaccurate.  I left a voicenote of 'Remember to take out the trash' and it transcribed it as 'Remember to take out the plan'.  It got 'two laundry' when I said 'do laundry'.  But still, Twilio is a very cool idea and it got my creative juices flowing.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/Xxp8ZNhs3ig" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2010/07/25/voicenotes-my-first-twilio-app.html</feedburner:origLink></entry>
 
 <entry>
   <title>Twilio &amp; Rails - 502 Bad Gateway Error Solution</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/z6HH2Bfed8g/twilio-rails-502-bad-gateway-error-solution.html" />
   <updated>2010-07-25T00:00:00-07:00</updated>
   <id>http://liahhansen.com/2010/07/25/twilio-rails-502-bad-gateway-error-solution</id>
   <content type="html">&lt;h1&gt;Twilio &amp;amp; Rails - 502 Bad Gateway Error Solution&lt;/h1&gt;

&lt;p&gt;I ran into an issue while writing a Twilio app in Rails where Twilio kept getting a 502 bad gateway error.  The url I was using was definitely working, so that wasn't the issue.  I did a little google sleuthing and the answer is putting the following code into the controller:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="n"&gt;skip_before_filter&lt;/span&gt; &lt;span class="ss"&gt;:verify_authenticity_token&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/z6HH2Bfed8g" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2010/07/25/twilio-rails-502-bad-gateway-error-solution.html</feedburner:origLink></entry>
 
 <entry>
   <title>Push to Heroku from a Branch of Your Local Git Repository</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/wnBzO6wDkPQ/push-to-heroku-from-a-branch-of-your-local-git-repository-other-than-master.html" />
   <updated>2010-02-25T00:00:00-08:00</updated>
   <id>http://liahhansen.com/2010/02/25/push-to-heroku-from-a-branch-of-your-local-git-repository-other-than-master</id>
   <content type="html">&lt;h1&gt;Push to Heroku from a Branch of Your Local Git Repository&lt;/h1&gt;

&lt;p&gt;We spent some time searching for a bit of git hocus pocus to solve this one...here's the spell:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git push heroku &amp;lt;branch_name&gt;:master&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Our situation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A production server&lt;/li&gt;
&lt;li&gt;A staging server&lt;/li&gt;
&lt;li&gt;A sandbox server&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;We have a branch in our git repo for the sandbox server &amp;amp; needed to be able to push straight from that, not from master.  The little colon did the trick!&lt;/p&gt;

&lt;p&gt;A couple resources:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.mail-archive.com/heroku@googlegroups.com/msg04039.html"&gt;http://www.mail-archive.com/heroku@googlegroups.com/msg04039.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://suitmymind.com/blog/2009/06/02/deploying-multiple-environments-on-heroku-while-still-hosting-code-on-github/"&gt;http://suitmymind.com/blog/2009/06/02/deploying-multiple-environments-on-heroku-while-still-hosting-code-on-github/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/wnBzO6wDkPQ" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2010/02/25/push-to-heroku-from-a-branch-of-your-local-git-repository-other-than-master.html</feedburner:origLink></entry>
 
 <entry>
   <title>Git Workshop Retrospective</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/lSzRb9M57qI/git-workshop-retrospective.html" />
   <updated>2010-02-25T00:00:00-08:00</updated>
   <id>http://liahhansen.com/2010/02/25/git-workshop-retrospective</id>
   <content type="html">&lt;h1&gt;Git Workshop Retrospective&lt;/h1&gt;

&lt;p&gt;I was elated with how well the workshop was received.  All 22 open spots were taken on meetup.com and we had 100% of those people show up!  There were still around 12 people on the waiting list.  Five women participated (including me), making the gender balance 23% female...not too shabby! Everyone was snug in our small space at Blazing Cloud, but it worked.&lt;/p&gt;

&lt;p&gt;I think that the hands on approach was very effective.  First I had everyone pair off and work together to research one of the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;when to use cherry-pick&lt;/li&gt;
&lt;li&gt;when to use checkout (branch &amp;amp; files)&lt;/li&gt;
&lt;li&gt;when to use merge&lt;/li&gt;
&lt;li&gt;when to use reset&lt;/li&gt;
&lt;li&gt;when to use revert&lt;/li&gt;
&lt;li&gt;when to use rebase&lt;/li&gt;
&lt;li&gt;when to use branch vs stash&lt;/li&gt;
&lt;li&gt;how to ignore files&lt;/li&gt;
&lt;li&gt;find as many ways to add &amp;amp; commit as you can (all the options &amp;amp; flags, what they do)&lt;/li&gt;
&lt;li&gt;how to delete files properly&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Then each pair reported back with their findings.  The discussion was great, made even better when Brian Colfer, my co-organizer &amp;amp; git expert came by and explained complex git concepts articulately.&lt;/p&gt;

&lt;p&gt;We switched gears and each pair completed an exercise I prepared.  All the materials for the exercise are online at &lt;a href="http://gitworkshop.com"&gt;gitworkshop.com&lt;/a&gt;.  The scenario included a boss who barked out indecisive orders that gave us opportunities to &lt;code&gt;git reset&lt;/code&gt;, &lt;code&gt;git revert&lt;/code&gt;, &lt;code&gt;git stash&lt;/code&gt;, &lt;code&gt;git cherry-pick&lt;/code&gt;, &lt;code&gt;git merge&lt;/code&gt; and &lt;code&gt;git branch&lt;/code&gt;.  I learned a ton creating the tutorial (spent at least 12 hours doing it...plenty of time to get a good grasp of git).&lt;/p&gt;

&lt;p&gt;My impression was that the participants learned a lot and had a good time!&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/lSzRb9M57qI" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2010/02/25/git-workshop-retrospective.html</feedburner:origLink></entry>
 
 <entry>
   <title>Git Workshop</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/8EHkyiICX-E/git-workshop.html" />
   <updated>2010-02-20T00:00:00-08:00</updated>
   <id>http://liahhansen.com/2010/02/20/git-workshop</id>
   <content type="html">&lt;h1&gt;Git Workshop&lt;/h1&gt;

&lt;p&gt;I've been using git since I started learning Ruby in July 2009.  I've gone through many of the more advanced topics - creating branches, checking them out &amp;amp; merging them is clear to me...that is until it isn't clear.  Sometimes git does things I'm not expecting.  So, I figured I'd host a little hands-on workshop to try to work out git intricacies.  There is nothing like teaching a topic to learn it inside &amp;amp; out.&lt;/p&gt;

&lt;p&gt;&lt;a href='http://www.meetup.com/sfruby/calendar/12628370/'&gt;More info about the workshop...&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/8EHkyiICX-E" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2010/02/20/git-workshop.html</feedburner:origLink></entry>
 
 <entry>
   <title>Understanding How Ruby Blocks Work</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/RbHTBR7wxVQ/understanding-how-ruby-blocks-work.html" />
   <updated>2010-01-28T00:00:00-08:00</updated>
   <id>http://liahhansen.com/2010/01/28/understanding-how-ruby-blocks-work</id>
   <content type="html">&lt;h1&gt;Understanding How Ruby Blocks Work&lt;/h1&gt;

&lt;p&gt;I've been preparing the curriculum for a class about Ruby blocks.  The word "block" just means a block of code that gets passed to a method right after other parameters.  When a block is sent to a method, the code within it is then available to the method.  The method can call the block of code any time it wants to using the "yield" keyword.  To sum it up, the two important pieces of blocks, are:&lt;/p&gt;

&lt;h1&gt;the code block&lt;/h1&gt;

&lt;h1&gt;the yield keyword&lt;/h1&gt;

&lt;p&gt;Look below...first I write my method, dos_veces.  When I call dos_veces, I add some code to the end of it between curly braces {...}.  That code gets executed by the method whenever I typed "yield" within my method definition.&lt;/p&gt;

&lt;p&gt;&lt;img src='http://lh3.ggpht.com/_oEW94elB_a8/S1OmehH1OSI/AAAAAAAAADw/wJjWf5g20EU/blocks_dos_veces.png' width='400px'/&gt;
&lt;img src='http://lh3.ggpht.com/_oEW94elB_a8/S1OoUyBUgvI/AAAAAAAAAD4/dQqqls41HJY/super_powers_blocks.png' width='400px'/&gt;&lt;/p&gt;

&lt;p&gt;I've found a few extremely helpful websites including: &lt;a href='http://eli.thegreenplace.net/2006/04/18/understanding-ruby-blocks-procs-and-methods/'&gt;Eli Bendersky's blog post about blocks procs and methods&lt;/a&gt;, &lt;a href='http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/'&gt;Robert Sosinski's blog post about blocks, procs and lamdas&lt;/a&gt;, &lt;a href='http://rubylearning.com/satishtalim/ruby_blocks.html'&gt;Ruby Learning: Blocks Tutorial&lt;/a&gt;, and &lt;a href='http://weblog.jamisbuck.org/2007/1/19/blocks-rock'&gt;Jamis Buck's blocks rock post&lt;/a&gt;.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/RbHTBR7wxVQ" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2010/01/28/understanding-how-ruby-blocks-work.html</feedburner:origLink></entry>
 
 <entry>
   <title>Double Colon</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/aZBlas1cVQY/double-colon.html" />
   <updated>2009-11-07T00:00:00-08:00</updated>
   <id>http://liahhansen.com/2009/11/07/double-colon</id>
   <content type="html">&lt;h1&gt;Double Colon&lt;/h1&gt;

&lt;p&gt;I'm reading Refactoring: Ruby Edition and I came across the double colon (::) operator.  I pretty much understand what it means, but I thought I'd do a little more research to get a better handle on its intricacies.  I came across the code below at http://en.wikibooks.org/wiki/Ruby_by_examples#::&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="no"&gt;CONST&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39; out there&amp;#39;&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Inside_one&lt;/span&gt;
    &lt;span class="no"&gt;CONST&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;proc&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39; in there&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;where_is_my_CONST&lt;/span&gt;
       &lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;CONST&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39; inside one&amp;#39;&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
 &lt;span class="k"&gt;end&lt;/span&gt;
 
 &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Inside_two&lt;/span&gt;
    &lt;span class="no"&gt;CONST&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39; inside two&amp;#39;&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;where_is_my_CONST&lt;/span&gt;
       &lt;span class="no"&gt;CONST&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
 &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;I thought I'd try it out in irb.  Here is the output:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="bash"&gt;&amp;gt;&amp;gt; puts Inside_one.new.where_is_my_CONST
 out there inside one

&amp;gt;&amp;gt; puts Inside_two.new.where_is_my_CONST
 inside two

&amp;gt;&amp;gt; puts Object::CONST + Inside_two::CONST
 out there inside two

&amp;gt;&amp;gt; puts Inside_two::CONST + CONST
 inside two out there

&amp;gt;&amp;gt; puts Inside_one::CONST
&lt;span class="c"&gt;#&amp;lt;Proc:0x00000001012ac4a0@(irb):3&amp;gt;&lt;/span&gt;

&amp;gt;&amp;gt; puts Inside_one::CONST.call + Inside_two::CONST
 in there inside two
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/aZBlas1cVQY" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2009/11/07/double-colon.html</feedburner:origLink></entry>
 
 <entry>
   <title>Search and Product Listing in Zen Cart</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/PoK99teVZ2g/search-and-product-listing-zen-cart.html" />
   <updated>2009-11-04T00:00:00-08:00</updated>
   <id>http://liahhansen.com/2009/11/04/search-and-product-listing-zen-cart</id>
   <content type="html">&lt;h1&gt;Search and Product Listing in Zen Cart&lt;/h1&gt;

&lt;p&gt;I've been working out some bugs in the search functionality that arose from some customization of the product listing.  The files I've been editing are scattered across many different folders and I thought it would be helpful to list all the files and what is in them.&lt;/p&gt;

&lt;p&gt;The heart of the product listing for both searches and category displays is held in a variable called $listing_sql. There are two files where $listing_sql is built:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;includes/index_filters/default_filter.php&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;includes/modules/pages/advanced_search_result/header_php.php&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;These files contain conditional statements that determine what SQL query should be executed.&lt;/p&gt;

&lt;p&gt;Both files send $listing_sql to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;includes/modules/product_listing.php&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;This file processes the SQL output into strings of html.&lt;/p&gt;
&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/PoK99teVZ2g" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2009/11/04/search-and-product-listing-zen-cart.html</feedburner:origLink></entry>
 
 <entry>
   <title>Symbol to Proc</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/QIu4oIEiJSs/symbol-to-proc.html" />
   <updated>2009-11-03T00:00:00-08:00</updated>
   <id>http://liahhansen.com/2009/11/03/symbol-to-proc</id>
   <content type="html">&lt;h1&gt;Symbol to Proc&lt;/h1&gt;

&lt;p&gt;I was tri-programing with S &amp;amp; B today, writing Selenium tests.  S typed:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="no"&gt;People&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;all&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="ss"&gt;:name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;into irb to demonstrate a database call.  I've seen this syntax before, but never understood what it meant. He said he didn't know, but that it worked. The output is an array of the names of all the People:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;Sandra&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Bob&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Fred&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Rosey&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;B explained that the ampersand followed by a symbol is a concise syntax for mapping the symbol object to a block.&lt;/p&gt;

&lt;p&gt;Here is a bit of playing with irb that illustrates how Symbol#to_proc works:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;People&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;all&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="c1"&gt;#&amp;lt;People id: 2, name: &amp;quot;Sandra&amp;quot;&amp;gt;, #&amp;lt;People id: 3, name: &amp;quot;Bob&amp;quot;&amp;gt;, #&amp;lt;People id: 4,  name: &amp;quot;Fred&amp;quot;&amp;gt;, #&amp;lt;People id: 5,  name: &amp;quot;Rosey&amp;quot;&amp;gt;]&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;People&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;all&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="ss"&gt;:name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;Sandra&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Bob&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Fred&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Rosey&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;People&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;all&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;collect&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;Sandra&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Bob&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Fred&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Rosey&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="ss"&gt;:name&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;to_proc&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;Proc:0x00002b720b0f45f8@/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/core_ext/symbol.rb:11&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;mything&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;proc&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;Proc:0x00002b720f91e950@/home/heroku_rack/lib/console.rb:133&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;People&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;all&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;mything&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;Sandra&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Bob&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Fred&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Rosey&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;People&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Ben&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="c1"&gt;#&amp;lt;People id: 9, created_at: &amp;quot;2009-11-02 13:25:55&amp;quot;, updated_at:&lt;/span&gt;
&lt;span class="s2"&gt;&amp;quot;2009-11-02 13:25:55&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Ben&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;creator_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kp"&gt;nil&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;People&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;all&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;mything&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;Sandra&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Bob&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Fred&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Rosey&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Ben&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;In a nutshell, the following two lines of code have the same result:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="no"&gt;People&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;all&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="ss"&gt;:name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="no"&gt;People&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;all&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/QIu4oIEiJSs" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2009/11/03/symbol-to-proc.html</feedburner:origLink></entry>
 
 <entry>
   <title>Let the Blogging Begin!</title>
   <link href="http://feedproxy.google.com/~r/liahhansen/~3/sv3Jl1Mnyy4/let-the-blogging-begin.html" />
   <updated>2009-09-06T00:00:00-07:00</updated>
   <id>http://liahhansen.com/2009/09/06/let-the-blogging-begin</id>
   <content type="html">&lt;h1&gt;Let the Blogging Begin!&lt;/h1&gt;

&lt;p&gt;UPDATE: As of March 2011 my blog has migrated from Radiant to Jekyll.&lt;/p&gt;

&lt;p&gt;I've been attending some amazing Ruby &amp;amp; RoR workshops and classes for the last month.  The whole time I've been wanting to blog about all of my breakthroughs with programming.  One of my RoR extracurriculars has been an informal meeting of 12-15 newbies every Sunday from 1-5 in a cottage belonging to our RoR teacher, Alex Chaffee.  We've built a humble - very, very humble blog app.  I was hoping to get it ready for prime time sooner and use it for my personal blog.  After three weeks we finally implemented authentication, but it still lacks in many areas, so I thought I'd use Radiant in the meantime.  It took me all of 10 minutes to install Radiant!  It is simple - much more barebones than Wordpress or Drupal, but it gets the job done while giving me a chance to watch RoR in action.   Here are all 12 lines of commands it takes to install:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;radiant -d sqlite3 liah-hansen&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;cd liah-hansen/&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;rake db:bootstrap&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git init&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;heroku create&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;heroku addons:add custom_domains&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;heroku domains:add liahhansen.com&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;heroku domains:add www.liahhansen.com&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git add .&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git commit -m "initial commit"&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;git push heroku master&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;heroku db:push&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Ta Da!&lt;/p&gt;

&lt;p&gt;Plus I changed this line in environment.rb:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;middleware&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;use&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Radiant&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Cache&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;to this:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;middleware&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;use&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Radiant&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Cache&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="ss"&gt;:entitystore&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;radiant:tmp/cache/entity&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="ss"&gt;:metastore&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;radiant:tmp/cache/meta&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;and I added a .gems file to the root directory:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="n"&gt;rspec&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;
&lt;span class="n"&gt;radiant&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;



&lt;img src="http://feeds.feedburner.com/~r/liahhansen/~4/sv3Jl1Mnyy4" height="1" width="1"/&gt;</content>
 <feedburner:origLink>http://liahhansen.com/2009/09/06/let-the-blogging-begin.html</feedburner:origLink></entry>
 
 
</feed>

