<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Counter202's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 08 Aug 2008 19:49:22 GMT</pubDate>
    <description>DZone Snippets: Counter202's Code Snippets</description>
    <item>
      <title>perl grep dir and filename</title>
      <link>http://snippets.dzone.com/posts/show/5492</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;my($directory, $filename) = $text =~ m/(.*\/)(.*)$/;&lt;br /&gt;print "D=$directory, F=$filename\n&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 14 May 2008 20:03:25 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5492</guid>
      <author>counter202 (jensen)</author>
    </item>
    <item>
      <title>ruby Simple RSS Parsing</title>
      <link>http://snippets.dzone.com/posts/show/4067</link>
      <description>def fetch_rss_items(url, max_items = nil)&lt;br /&gt;  %w{open-uri rss/0.9 rss/1.0 rss/2.0 rss/parser}.each do |lib|&lt;br /&gt;    require(lib)&lt;br /&gt;  end&lt;br /&gt;  rss = RSS::Parser.parse(open(url).read)&lt;br /&gt;  rss.items[0...(max_items ? max_items : rss.items.length)]&lt;br /&gt;end&lt;br /&gt; &lt;br /&gt;items = fetch_rss_items('http://www.digg.com/rss/index.xml', 5)&lt;br /&gt;items.collect { |item| item.title }&lt;br /&gt;=&gt; ["Understanding AJAX - A Beginner's Guide",&lt;br /&gt;    "Anti-cancer Compound In Beer", ...]</description>
      <pubDate>Mon, 28 May 2007 08:25:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4067</guid>
      <author>counter202 (jensen)</author>
    </item>
    <item>
      <title>perl http post</title>
      <link>http://snippets.dzone.com/posts/show/4066</link>
      <description>use HTTP::Request::Common qw(POST);&lt;br /&gt;use LWP::UserAgent;&lt;br /&gt;&lt;br /&gt;my $user = "user";&lt;br /&gt;my $pass = "pass";&lt;br /&gt;&lt;br /&gt;my $browser = LWP::UserAgent-&gt;new();&lt;br /&gt;&lt;br /&gt;my $responde = HTTP::Request-&gt;new(POST =&gt; "http://www.sito.com/index.php");&lt;br /&gt;$responde-&gt;content_type("application/x-www-form-urlencoded");&lt;br /&gt;$responde-&gt;content("user=" . $user . "&amp;pass=" . $pass);&lt;br /&gt;&lt;br /&gt;$browser-&gt;request($responde)-&gt;as_string&lt;br /&gt;</description>
      <pubDate>Mon, 28 May 2007 08:20:29 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4066</guid>
      <author>counter202 (jensen)</author>
    </item>
    <item>
      <title>restart appache</title>
      <link>http://snippets.dzone.com/posts/show/3999</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;sudo apachectl restart&lt;br /&gt;..&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 12 May 2007 19:35:56 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3999</guid>
      <author>counter202 (jensen)</author>
    </item>
    <item>
      <title>iTunes DB  parser</title>
      <link>http://snippets.dzone.com/posts/show/3700</link>
      <description>// description of your code here&lt;br /&gt;This script sifts through your iTunes DB &lt;br /&gt;From:&lt;br /&gt;http://blog.zenspider.com/archives/2007/03/that_stupid_thing_i_wrote_the_other_day_part_2.html&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;require 'time'&lt;br /&gt;&lt;br /&gt;class Album &lt; Array&lt;br /&gt;  def age&lt;br /&gt;    map { |track| track.age }.max&lt;br /&gt;  end&lt;br /&gt;  def score&lt;br /&gt;    total / Math.log(age)&lt;br /&gt;  end&lt;br /&gt;  def total&lt;br /&gt;    inject(0.0) do |total_score, track|&lt;br /&gt;      total_score + track.score&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;  def self.parse(file)&lt;br /&gt;    today = Time.now&lt;br /&gt;    d = {}&lt;br /&gt;    library = Hash.new { |h,k| h[k] = Album.new }&lt;br /&gt;&lt;br /&gt;    IO.foreach(File.expand_path(file)) do |line|&lt;br /&gt;      if line =~ /&lt;key&gt;(Name|Artist|Album|Date Added|Play Count|Rating)&lt;\/key&gt;&lt;.*?&gt;(.*)&lt;\/.*?&gt;/ then&lt;br /&gt;        key = $1.downcase.split.first&lt;br /&gt;        val = $2&lt;br /&gt;        d[key.intern] = val&lt;br /&gt;&lt;br /&gt;        if d.size == 6 then&lt;br /&gt;          date = d[:date].sub(/T.*/, '')&lt;br /&gt;          key = "#{d[:album]} by #{d[:artist]}"&lt;br /&gt;          age = ((today - Time.parse(date)) / 86400.0).to_i&lt;br /&gt;          library[key] &lt;&lt; Track.new(age, d[:play].to_i, d[:rating].to_i / 20)&lt;br /&gt;&lt;br /&gt;          d.clear&lt;br /&gt;        end&lt;br /&gt;      end&lt;br /&gt;    end&lt;br /&gt;    library&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;Track = Struct.new(:age, :count, :rating)&lt;br /&gt;class Track&lt;br /&gt;  def score&lt;br /&gt;    rating * count.to_f&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;max = (ARGV.shift || 10).to_i&lt;br /&gt;file = ARGV.shift || "~/Music/iTunes/iTunes Music Library.xml"&lt;br /&gt;library = Album.parse(file)&lt;br /&gt;&lt;br /&gt;top = library.sort_by { |h,k| -k.score }[0...max]&lt;br /&gt;top.each_with_index do |(artist_album, album), c|&lt;br /&gt;  puts "%-3d = (%4d tot, %5.2f adj): %s" % [c+1, album.total, album.score, artist_album,]&lt;br /&gt;  album.each do |t|&lt;br /&gt;    puts "  #{t.age} days old, #{t.count} count, #{t.rating} rating = #{t.score}"&lt;br /&gt;  end if $DEBUG&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 19 Mar 2007 17:51:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3700</guid>
      <author>counter202 (jensen)</author>
    </item>
    <item>
      <title>io read file by byte</title>
      <link>http://snippets.dzone.com/posts/show/3153</link>
      <description>// description of your code here&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;f = File.new("c\:\\test.txt")&lt;br /&gt;checksum = 0&lt;br /&gt;f.each_byte {|x| &lt;br /&gt;checksum = checksum+x &lt;br /&gt;puts checksum&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 15 Dec 2006 00:37:24 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3153</guid>
      <author>counter202 (jensen)</author>
    </item>
    <item>
      <title>install soap4r</title>
      <link>http://snippets.dzone.com/posts/show/3152</link>
      <description>// install soap4r with gem , soap webservice lib &lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;gem install soap4r --source http://dev.ctor.org/download/&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 15 Dec 2006 00:10:07 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3152</guid>
      <author>counter202 (jensen)</author>
    </item>
  </channel>
</rss>
