<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>jvoorhis comments on A compelling alternative to Hpricot</title>
    <link>http://www.jvoorhis.com/</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>jvoorhis comments</description>
    <item>
      <title>"A compelling alternative to Hpricot": comment by cypherpunk</title>
      <description>&lt;p&gt;Beware of Randal Schwartz.  He&amp;#8217;s prone to handing out &lt;a href="http://partmaps.org/era/unix/award.html"&gt;Useless Use of Cat Awards&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Sun, 15 Apr 2007 04:47:19 NZST</pubDate>
      <guid>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-496</guid>
      <link>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-496</link>
    </item>
    <item>
      <title>"A compelling alternative to Hpricot": comment by amr</title>
      <description>&lt;code&gt; 
expr `cat input.txt | (tr '\n' +; echo 0) | bc` / `cat input.txt | wc -l `
&lt;/code&gt;

	&lt;p&gt;I think my prev comment was eaten by textile.&lt;/p&gt;</description>
      <pubDate>Fri, 13 Apr 2007 12:30:42 NZST</pubDate>
      <guid>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-495</guid>
      <link>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-495</link>
    </item>
    <item>
      <title>"A compelling alternative to Hpricot": comment by amr</title>
      <description>&lt;p&gt;Spoke too soon! I think this would do the averge thingy:&lt;/p&gt;


	&lt;p&gt;expr `cat comments.txt | (tr &amp;#8217;\n&amp;#8217; +; echo 0) | bc` / `cat comments.txt | wc -l `&lt;/p&gt;</description>
      <pubDate>Fri, 13 Apr 2007 12:29:17 NZST</pubDate>
      <guid>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-494</guid>
      <link>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-494</link>
    </item>
    <item>
      <title>"A compelling alternative to Hpricot": comment by amr</title>
      <description>&lt;p&gt;Heh :) actually just that very day I was doing a one liner in ksh &amp;#38; friends on HP/UX to sum up the disk sizes on one of our boxes and I had to use &lt;span class="caps"&gt;AWK&lt;/span&gt; variables to sum the sizes up in the pipeline. I checked out bc quickly but couldn&amp;#8217;t find anything that would sum/avg a stream of numbers in a pipeline.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;d really love to see bc -avg -i &lt;list of nums&gt; capability (or something like that), please point me to one if someone knows it. I looked up and down that man page but was too hurried to futz around too much.&lt;/p&gt;</description>
      <pubDate>Fri, 13 Apr 2007 12:13:13 NZST</pubDate>
      <guid>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-493</guid>
      <link>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-493</link>
    </item>
    <item>
      <title>"A compelling alternative to Hpricot": comment by cypherpunk</title>
      <description>&lt;p&gt;I couldn&amp;#8217;t find avg, either, so I decided to implement it as a shell function:&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;function avg () {
  n=0 
  sum=0 
  while read i
  do
    n=$(( n + 1 )) 
    sum=$(( sum + i )) 
  done
  echo $sum / $n | bc -l
}&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Thu, 12 Apr 2007 14:06:11 NZST</pubDate>
      <guid>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-491</guid>
      <link>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-491</link>
    </item>
    <item>
      <title>"A compelling alternative to Hpricot": comment by JV</title>
      <description>&lt;p&gt;@amr&lt;/p&gt;


	&lt;p&gt;I wondered if anyone would catch that ;) &lt;code&gt;avg&lt;/code&gt; is this thing that I wrote a while ago that reads lists of numbers and, well, averages them. This is all:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
#!/usr/bin/env ruby

module Enumerable
  def sum
    self.inject(0.0) { |s,e| s + e.to_f }
  end
  def avg
    sum / size.to_f
  end
end

data = ARGF.read.split($/)
puts data.avg
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;That is not the only utility of its kind I have. I am surprised there aren&amp;#8217;t more command line tools for statistical processing.&lt;/p&gt;</description>
      <pubDate>Thu, 12 Apr 2007 14:04:52 NZST</pubDate>
      <guid>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-490</guid>
      <link>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-490</link>
    </item>
    <item>
      <title>"A compelling alternative to Hpricot": comment by amr</title>
      <description>&lt;p&gt;I see, &amp;#8220;avg&amp;#8221; isn&amp;#8217;t a builtin in zsh is it? mine on osx doesn&amp;#8217;t seem to have it.&lt;/p&gt;</description>
      <pubDate>Thu, 12 Apr 2007 13:40:34 NZST</pubDate>
      <guid>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-489</guid>
      <link>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-489</link>
    </item>
    <item>
      <title>"A compelling alternative to Hpricot": comment by cypherpunk</title>
      <description>&lt;p&gt;&lt;a href="http://www.unixreview.com/documents/s=8274/sam0306g/"&gt;xargs&lt;/a&gt; is my secret iterating weapon.&lt;/p&gt;</description>
      <pubDate>Thu, 12 Apr 2007 01:11:07 NZST</pubDate>
      <guid>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-488</guid>
      <link>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-488</link>
    </item>
    <item>
      <title>"A compelling alternative to Hpricot": comment by JV</title>
      <description>&lt;p&gt;I use zsh, but the above should run just fine in anything sh-compatible.&lt;/p&gt;</description>
      <pubDate>Wed, 11 Apr 2007 15:02:39 NZST</pubDate>
      <guid>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-487</guid>
      <link>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-487</link>
    </item>
    <item>
      <title>"A compelling alternative to Hpricot": comment by amr</title>
      <description>&lt;p&gt;Jeremy, what shell did you use?&lt;/p&gt;


	&lt;p&gt;I second the &amp;#8220;Ruby-esqe&amp;#8221; comment :) I did a double take lol!&lt;/p&gt;</description>
      <pubDate>Wed, 11 Apr 2007 13:06:36 NZST</pubDate>
      <guid>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-486</guid>
      <link>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-486</link>
    </item>
    <item>
      <title>"A compelling alternative to Hpricot": comment by JV</title>
      <description>&lt;p&gt;Thanks! But it&amp;#8217;s not as Ruby-esque as I would like, since &lt;code&gt;until&lt;/code&gt;, &lt;code&gt;while&lt;/code&gt; and &lt;code&gt;for&lt;/code&gt; were the only iterators I had to play with.&lt;/p&gt;


	&lt;p&gt;Although this is a trivial example, I think the following ideas let me bang out a trivial implementation:&lt;/p&gt;


	&lt;ol&gt;
	&lt;li&gt;Translating the problem to a simpler domain &amp;#8211; &lt;span class="caps"&gt;HTML&lt;/span&gt; parsing is substituted by simple regular expressions.&lt;/li&gt;
		&lt;li&gt;Composing small, focused components to build a solution.&lt;/li&gt;
		&lt;li&gt;Exploiting the capabilities of a tool beyond its intended use &amp;#8211; &lt;code&gt;lynx&lt;/code&gt; is a browser, but I wanted a tool that would download document, parse it into semi-structured text, and get out of the way.&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;These are all good ideas that can be put to work while composing throw-away solutions for prototyping or problem solving.&lt;/p&gt;</description>
      <pubDate>Wed, 11 Apr 2007 08:31:55 NZST</pubDate>
      <guid>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-485</guid>
      <link>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-485</link>
    </item>
    <item>
      <title>"A compelling alternative to Hpricot": comment by cypherpunk</title>
      <description>&lt;h2&gt;&amp;#8220;How could anything be better than Hpricot?!!&amp;#8221;&lt;/h2&gt;


	&lt;p&gt;When I read the blog title, I was a little scared, because I&amp;#8217;ve grown to like Hpricot &lt;a href="http://balloon.hobix.com/~cypherpunk"&gt;a lot&lt;/a&gt; .  The thought of Hpricot being marginalized made me feel almost &amp;#8230;threatened.  Irrational?  Perhaps.  But I am only human.&lt;/p&gt;


	&lt;p&gt;With that said, I must say that that is some fine shell scripting you have there.
It also looks very ruby-esque.&lt;/p&gt;</description>
      <pubDate>Wed, 11 Apr 2007 06:27:54 NZST</pubDate>
      <guid>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-484</guid>
      <link>http://www.jvoorhis.com/articles/2007/04/11/a-compelling-alternative-to-hpricot#comment-484</link>
    </item>
    <item>
      <title>"A compelling alternative to Hpricot" by jvoorhis</title>
      <description>&lt;p&gt;After re-reading Nat Pryce&amp;#8217;s &lt;a href="http://nat.truemesh.com/archives/000555.html"&gt;Scrapheap Challege writeup&lt;/a&gt;, I tried to see how easily I could answer a simple question with only &lt;code&gt;lynx&lt;/code&gt;, &lt;code&gt;grep&lt;/code&gt; and friends. It turns out to be even simpler than I suspected. For example, the following tells me that my average blog post receives 2.2 comments.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
# iterate through 17 pages
page=1; until [ $page -eq 17 ] ; do
  lynx -dump "http://www.jvoorhis.com/articles/page/$page" | \
    egrep "([[:digit:]]+|no) comments?" | \
    sed -e "s/\[.*\]//g" -e "s/no/0/g" | \
    awk '{print $1}' &amp;gt;&amp;gt; comments.txt
  page=$(( page + 1 ))
done
avg comments.txt 
&lt;/code&lt;/pre&gt;

</description>
      <pubDate>Wed, 11 Apr 2007 03:52:00 NZST</pubDate>
      <guid>&lt;a href="/articles/2007/04/11/a-compelling-alternative-to-hpricot"&gt;A compelling alternative to Hpricot&lt;/a&gt;</guid>
      <link>&lt;a href="/articles/2007/04/11/a-compelling-alternative-to-hpricot"&gt;A compelling alternative to Hpricot&lt;/a&gt;</link>
    </item>
  </channel>
</rss>
