<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.dzone.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>DZone Snippets: Store, sort and share source code, with tag goodness</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 12 Jul 2009 20:53:09 GMT</pubDate>
    <description>DZone Snippets: Store, sort and share source code, with tag goodness</description>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://snippets.dzone.com/rss" type="application/rss+xml" /><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Fsnippets.dzone.com%2Frss" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Fsnippets.dzone.com%2Frss" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Fsnippets.dzone.com%2Frss" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://snippets.dzone.com/rss" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Fsnippets.dzone.com%2Frss" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Fsnippets.dzone.com%2Frss" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Fsnippets.dzone.com%2Frss" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><item>
      <title>Forward XMPP messages using XMPP4R</title>
      <link>http://feeds.dzone.com/~r/dzone/snippets/~3/189e0jkatcI/7584</link>
      <description>This script forwards received XMPP messages to james@jamesrobertson.eu. This allows messages to forward to an artificially intelligent bot, RSS creation service etc.
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;
&lt;br /&gt;#!/usr/bin/ruby
&lt;br /&gt;#file: xmppserver_jeeves_forwarder.rb
&lt;br /&gt;
&lt;br /&gt;require 'rubygems'  
&lt;br /&gt;require 'xmpp4r-simple'
&lt;br /&gt;
&lt;br /&gt;def action_msg(messenger, buddy, message)
&lt;br /&gt;  username, body = message.match(/(.[^:]+): (.*)/).captures
&lt;br /&gt;  puts 'username : ' + username + ' - body : ' + body
&lt;br /&gt;  messenger.deliver('james@jamesrobertson.eu', message)
&lt;br /&gt;end
&lt;br /&gt;
&lt;br /&gt;username = 'jeeves2'
&lt;br /&gt;password = 'secret'
&lt;br /&gt;
&lt;br /&gt;puts "connecting to jabber server.."  
&lt;br /&gt;messenger = Jabber::Simple.new(username+'@jabber.com',password)  
&lt;br /&gt;puts "connected."  
&lt;br /&gt;
&lt;br /&gt;while true
&lt;br /&gt;  messenger.received_messages do |msg|  
&lt;br /&gt;    buddy = msg.from
&lt;br /&gt;    #puts '-' + msg.from.to_s + ' ' + msg.body.to_s
&lt;br /&gt;    action_msg(messenger,buddy, msg.body)
&lt;br /&gt;  end  
&lt;br /&gt;  sleep 2
&lt;br /&gt;end  
&lt;br /&gt;&lt;/code&gt;&lt;img src="http://feeds.feedburner.com/~r/dzone/snippets/~4/189e0jkatcI" height="1" width="1"/&gt;</description>
      <pubDate>Sun, 12 Jul 2009 20:00:36 GMT</pubDate>
      <guid isPermaLink="false">http://snippets.dzone.com/posts/show/7584</guid>
      <author>jrobertson (James Robertson)</author>
    <feedburner:origLink>http://snippets.dzone.com/posts/show/7584</feedburner:origLink></item>
    <item>
      <title>See the most recent dent from all your identi.ca friends.</title>
      <link>http://feeds.dzone.com/~r/dzone/snippets/~3/N3nR_kNAVM4/7583</link>
      <description>&lt;code&gt;
&lt;br /&gt;#!/usr/bin/ruby
&lt;br /&gt;#file: xmppserver_jeeves2b.rb
&lt;br /&gt;
&lt;br /&gt;require 'rubygems'  
&lt;br /&gt;require 'xmpp4r-simple'
&lt;br /&gt;
&lt;br /&gt;require 'rexml/document'
&lt;br /&gt;include REXML
&lt;br /&gt;
&lt;br /&gt;def new_friend(doc, username)
&lt;br /&gt;xml =&lt;&lt;XML
&lt;br /&gt;    &lt;friend&gt;
&lt;br /&gt;      &lt;username&gt;#{username}&lt;/username&gt;
&lt;br /&gt;      &lt;notice&gt;&lt;/notice&gt;
&lt;br /&gt;      &lt;date&gt;&lt;/date&gt;
&lt;br /&gt;    &lt;/friend&gt;
&lt;br /&gt;XML
&lt;br /&gt;  friend = Document.new(xml).root
&lt;br /&gt;  doc.root.elements['records'].add_element friend
&lt;br /&gt;  friend
&lt;br /&gt;end
&lt;br /&gt;
&lt;br /&gt;def update(friend, message)
&lt;br /&gt;  friend.elements['notice'].text = message
&lt;br /&gt;  friend.elements['date'].text = Time.now.strftime("%Y-%m-%dT%H:%M:%S%z")
&lt;br /&gt;end
&lt;br /&gt;
&lt;br /&gt;  def action_msg(messenger, buddy, message)
&lt;br /&gt;    username, body = message.match(/(.[^:]+): (.*)/).captures
&lt;br /&gt;    puts 'username : ' + username + ' - body : ' + body
&lt;br /&gt;    doc = Document.new(File.open('identica_friends.xml','r').read)
&lt;br /&gt;    friend = doc.root.elements["records/friend[username='#{username}']"]
&lt;br /&gt;
&lt;br /&gt;    friend = new_friend(doc, username) unless friend.is_a? Element
&lt;br /&gt;    update(friend, body) 
&lt;br /&gt;    File.open('identica_friends.xml','w'){|f| f.write doc.write}
&lt;br /&gt;
&lt;br /&gt;  end
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;username = 'jeeves2'
&lt;br /&gt;password = 'secret'
&lt;br /&gt;
&lt;br /&gt;puts "connecting to jabber server.."  
&lt;br /&gt;messenger = Jabber::Simple.new(username+'@jabber.com',password)  
&lt;br /&gt;puts "connected."  
&lt;br /&gt;
&lt;br /&gt;while true
&lt;br /&gt;  messenger.received_messages do |msg|  
&lt;br /&gt;    buddy = msg.from
&lt;br /&gt;    #puts '-' + msg.from.to_s + ' ' + msg.body.to_s
&lt;br /&gt;    action_msg(messenger,buddy, msg.body)
&lt;br /&gt;  end  
&lt;br /&gt;  sleep 2
&lt;br /&gt;end  
&lt;br /&gt;&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;output extract:
&lt;br /&gt;&lt;pre&gt;
&lt;br /&gt;    &lt;friend&gt;  
&lt;br /&gt;      &lt;username&gt;dantheman&lt;/username&gt;
&lt;br /&gt;      &lt;notice&gt;@lucy Fixed the license on the old site shedmusic.net, that contai
&lt;br /&gt;ns a lot more music and might be of more use at the moment :)&lt;/notice&gt;
&lt;br /&gt;      &lt;date&gt;2009-07-12T17:08:19+0100&lt;/date&gt;
&lt;br /&gt;    &lt;/friend&gt;
&lt;br /&gt;    &lt;friend&gt;
&lt;br /&gt;      &lt;username&gt;appropedia&lt;/username&gt;
&lt;br /&gt;      &lt;notice&gt;any horoscope seems ‘true’ if it tells you that you are highly att
&lt;br /&gt;ractive to the opposite sex and your worst fault is generosity. ~Orwell !q&lt;/noti
&lt;br /&gt;ce&gt;
&lt;br /&gt;      &lt;date&gt;2009-07-12T17:00:50+0100&lt;/date&gt;
&lt;br /&gt;    &lt;/friend&gt;
&lt;br /&gt;    &lt;friend&gt;
&lt;br /&gt;      &lt;username&gt;mjray&lt;/username&gt;
&lt;br /&gt;      &lt;notice&gt;@noodles yes, but please run for www.spi-inc.org board all the sam
&lt;br /&gt;e&lt;/notice&gt;
&lt;br /&gt;      &lt;date&gt;2009-07-12T17:03:37+0100&lt;/date&gt;
&lt;br /&gt;    &lt;/friend&gt;
&lt;br /&gt;    &lt;friend&gt;
&lt;br /&gt;      &lt;username&gt;itnet7&lt;/username&gt;
&lt;br /&gt;      &lt;notice&gt;Heading off to Stardust Coffee and Video locate in Winterpark for 
&lt;br /&gt;a Florida Team !ubuntufl  !ubuntu Bug Jam!! Stop by if you want!&lt;/notice&gt;
&lt;br /&gt;      &lt;date&gt;2009-07-12T17:09:42+0100&lt;/date&gt;
&lt;br /&gt;    &lt;/friend&gt;
&lt;br /&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;Then use an XSLT file to transform the XML file to RSS:
&lt;br /&gt;&lt;pre&gt;
&lt;br /&gt;&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"&gt;
&lt;br /&gt;
&lt;br /&gt;	&lt;xsl:output method="xml" encoding="UTF-8" indent="yes"  /&gt;
&lt;br /&gt;
&lt;br /&gt;	&lt;xsl:template match="friends"&gt;
&lt;br /&gt;
&lt;br /&gt;		&lt;rss version="2.0"&gt;	
&lt;br /&gt;		&lt;channel&gt;
&lt;br /&gt;		&lt;title&gt;Identi.ca friends' most recent dents&lt;/title&gt;
&lt;br /&gt;		&lt;link&gt;&lt;/link&gt;
&lt;br /&gt;		&lt;description&gt;Identi.ca/jrobertson friends' most recent decents&lt;/description&gt;
&lt;br /&gt;
&lt;br /&gt;  	&lt;language&gt;en&lt;/language&gt;
&lt;br /&gt;
&lt;br /&gt;	&lt;xsl:apply-templates select="records/friend[position() &amp;lt; 6]"&gt;
&lt;br /&gt;          &lt;xsl:sort select="date" order="descending"/&gt;
&lt;br /&gt;        &lt;/xsl:apply-templates&gt;
&lt;br /&gt;
&lt;br /&gt;		&lt;/channel&gt;
&lt;br /&gt;		&lt;/rss&gt;
&lt;br /&gt;
&lt;br /&gt;	&lt;/xsl:template&gt;
&lt;br /&gt;
&lt;br /&gt;	&lt;xsl:template match="records/friend"&gt;
&lt;br /&gt;
&lt;br /&gt;	&lt;item&gt;
&lt;br /&gt;		&lt;title&gt;&lt;xsl:value-of select="username"/&gt;: &lt;xsl:value-of select="notice"/&gt;&lt;/title&gt;
&lt;br /&gt;		&lt;link&gt;&lt;/link&gt;
&lt;br /&gt;		&lt;description&gt;&lt;xsl:value-of select="username"/&gt;: &lt;xsl:value-of select="notice"/&gt;&lt;/description&gt;
&lt;br /&gt;	&lt;/item&gt;
&lt;br /&gt;
&lt;br /&gt;	&lt;/xsl:template&gt;	
&lt;br /&gt;
&lt;br /&gt;&lt;/xsl:stylesheet&gt;
&lt;br /&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;e.g.
&lt;br /&gt;&lt;pre&gt;
&lt;br /&gt;james@felice:~/ruby$ xsltproc identica_friends.xsl identica_friends.xml &gt; identica_friends.rss
&lt;br /&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;Here's the final RSS file:
&lt;br /&gt;&lt;pre&gt;
&lt;br /&gt;&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;br /&gt;&lt;rss version="2.0"&gt;
&lt;br /&gt;  &lt;channel&gt;
&lt;br /&gt;    &lt;title&gt;Identi.ca friends' most recent dents&lt;/title&gt;
&lt;br /&gt;    &lt;link/&gt;
&lt;br /&gt;    &lt;description&gt;Identi.ca/jrobertson friends' most recent decents&lt;/description&gt;
&lt;br /&gt;    &lt;language&gt;en&lt;/language&gt;
&lt;br /&gt;    &lt;item&gt;
&lt;br /&gt;      &lt;title&gt;uberchick: uberchick is breathing deeply &amp;amp; trying to distract herself...she's sorry for boring update....&lt;/title&gt;
&lt;br /&gt;      &lt;link/&gt;
&lt;br /&gt;      &lt;description&gt;uberchick: uberchick is breathing deeply &amp;amp; trying to distract herself...she's sorry for boring update....&lt;/description&gt;
&lt;br /&gt;      &lt;published&gt;2009-07-12T17:14:07+0100&lt;/published&gt;
&lt;br /&gt;    &lt;/item&gt;
&lt;br /&gt;    &lt;item&gt;
&lt;br /&gt;      &lt;title&gt;dantheman: @lucy Fixed the license on the old site shedmusic.net, that contains a lot more music and might be of more use at the moment :)&lt;/title&gt;
&lt;br /&gt;      &lt;link/&gt;
&lt;br /&gt;      &lt;description&gt;dantheman: @lucy Fixed the license on the old site shedmusic.net, that contains a lot more music and might be of more use at the moment :)&lt;/description&gt;
&lt;br /&gt;      &lt;published&gt;2009-07-12T17:08:19+0100&lt;/published&gt;
&lt;br /&gt;    &lt;/item&gt;
&lt;br /&gt;    &lt;item&gt;
&lt;br /&gt;      &lt;title&gt;mjray: @noodles yes, but please run for www.spi-inc.org board all the same&lt;/title&gt;
&lt;br /&gt;      &lt;link/&gt;
&lt;br /&gt;      &lt;description&gt;mjray: @noodles yes, but please run for www.spi-inc.org board all the same&lt;/description&gt;
&lt;br /&gt;      &lt;published&gt;2009-07-12T17:03:37+0100&lt;/published&gt;
&lt;br /&gt;    &lt;/item&gt;
&lt;br /&gt;    &lt;item&gt;
&lt;br /&gt;      &lt;title&gt;appropedia: any horoscope seems ‘true’ if it tells you that you are highly attractive to the opposite sex and your worst fault is generosity. ~Orwell !q&lt;/title&gt;
&lt;br /&gt;      &lt;link/&gt;
&lt;br /&gt;      &lt;description&gt;appropedia: any horoscope seems ‘true’ if it tells you that you are highly attractive to the opposite sex and your worst fault is generosity. ~Orwell !q&lt;/description&gt;
&lt;br /&gt;      &lt;published&gt;2009-07-12T17:00:50+0100&lt;/published&gt;
&lt;br /&gt;    &lt;/item&gt;
&lt;br /&gt;  &lt;/channel&gt;
&lt;br /&gt;&lt;/rss&gt;
&lt;br /&gt;&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/dzone/snippets/~4/N3nR_kNAVM4" height="1" width="1"/&gt;</description>
      <pubDate>Sun, 12 Jul 2009 15:46:34 GMT</pubDate>
      <guid isPermaLink="false">http://snippets.dzone.com/posts/show/7583</guid>
      <author>jrobertson (James Robertson)</author>
    <feedburner:origLink>http://snippets.dzone.com/posts/show/7583</feedburner:origLink></item>
    <item>
      <title>Use the ISO 8601 Internet Date/Time Format</title>
      <link>http://feeds.dzone.com/~r/dzone/snippets/~3/J9V09NW5vQ8/7582</link>
      <description>This is an example of the format mask used to primarily display the UTC ISO 8601 Internet Date/Time Format in Ruby.
&lt;br /&gt;
&lt;br /&gt;&lt;pre&gt;
&lt;br /&gt;james@felice:~/ruby$ dfh "`date +"%Y-%m-%dT%H:%M:%S%z"`"
&lt;br /&gt;2009-07-12T15:39:11+0100
&lt;br /&gt;%Y-%m-%dT%H:%M:%S%z
&lt;br /&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;It's worth noting that the Ruby Date and Time format is exactly the same as it is in the Bash shell.
&lt;br /&gt;
&lt;br /&gt;Resources:
&lt;br /&gt; - &lt;a href="https://identi.ca/api/statuses/public_timeline.atom"&gt;Identi.ca public timeline&lt;/a&gt; [identi.ca]
&lt;br /&gt; - &lt;a href="http://tools.ietf.org/html/rfc3339#section-5"&gt;RFC 3339 - Date and Time on the Internet: Timestamps&lt;/a&gt; [ietf.org]
&lt;br /&gt; - &lt;a href="http://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/"&gt;How to format date for display or to use in a shell script&lt;/a&gt; [cyberciti.biz]
&lt;br /&gt; - &lt;a href="http://snippets.dzone.com/posts/show/7579"&gt;Use a date format helper&lt;/a&gt; [dzone.com]&lt;img src="http://feeds.feedburner.com/~r/dzone/snippets/~4/J9V09NW5vQ8" height="1" width="1"/&gt;</description>
      <pubDate>Sun, 12 Jul 2009 14:54:23 GMT</pubDate>
      <guid isPermaLink="false">http://snippets.dzone.com/posts/show/7582</guid>
      <author>jrobertson (James Robertson)</author>
    <feedburner:origLink>http://snippets.dzone.com/posts/show/7582</feedburner:origLink></item>
    <item>
      <title>Print out the date of every Sunday between two dates</title>
      <link>http://feeds.dzone.com/~r/dzone/snippets/~3/qEYDksb2xwc/7581</link>
      <description>Source: &lt;a href="http://www.ruby-doc.org/stdlib/libdoc/date/rdoc/index.html"&gt;date: Ruby Standard Library Documentation&lt;/a&gt; [ruby-doc.org] 
&lt;br /&gt;
&lt;br /&gt;&lt;snip&gt;
&lt;br /&gt;&lt;code&gt;
&lt;br /&gt;def print_sundays(d1, d2)
&lt;br /&gt;    d1 +=1 while (d1.wday != 0)
&lt;br /&gt;    d1.step(d2, 7) do |date|
&lt;br /&gt;        puts "#{Date::MONTHNAMES[date.mon]} #{date.day}"
&lt;br /&gt;    end
&lt;br /&gt;end
&lt;br /&gt;
&lt;br /&gt;print_sundays(Date::civil(2003, 4, 8), Date::civil(2003, 5, 23))
&lt;br /&gt;&lt;/code&gt;
&lt;br /&gt;&lt;/snip&gt;
&lt;br /&gt;output:
&lt;br /&gt;&lt;pre&gt;    
&lt;br /&gt;April 13
&lt;br /&gt;April 20
&lt;br /&gt;April 27
&lt;br /&gt;May 4
&lt;br /&gt;May 11
&lt;br /&gt;May 18
&lt;br /&gt;&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/dzone/snippets/~4/qEYDksb2xwc" height="1" width="1"/&gt;</description>
      <pubDate>Sun, 12 Jul 2009 13:03:31 GMT</pubDate>
      <guid isPermaLink="false">http://snippets.dzone.com/posts/show/7581</guid>
      <author>jrobertson (James Robertson)</author>
    <feedburner:origLink>http://snippets.dzone.com/posts/show/7581</feedburner:origLink></item>
    <item>
      <title>Use a date format helper</title>
      <link>http://feeds.dzone.com/~r/dzone/snippets/~3/GCKwkIJIlII/7579</link>
      <description>This code makes it easier to format a date or time just by explicitly entering how you want it to look.
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;
&lt;br /&gt;class String
&lt;br /&gt;  def to_strftime()
&lt;br /&gt;    switches = %w(%a %A %d %e %b %m %B %y %Y %M %H %I %p)
&lt;br /&gt;    masks = switches.map {|switch| [Time.now.strftime("#{switch}"), switch]}
&lt;br /&gt;    h = Hash[*masks.flatten]
&lt;br /&gt;  
&lt;br /&gt;    self.gsub(/[a-zA-Z0-9]+/) {|x| h[x]}
&lt;br /&gt;  end
&lt;br /&gt;end
&lt;br /&gt;&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;examples:
&lt;br /&gt;&lt;pre&gt;
&lt;br /&gt;"Fri 10 Jul, 20:27".to_strftime
&lt;br /&gt;=&gt; "%a %e %b, %H:%M"
&lt;br /&gt;"Fri 10 Jul 2009, 20:28".to_strftime
&lt;br /&gt;=&gt; "%a %e %b %Y, %H:%M"
&lt;br /&gt;"Friday 10 July 2009, 20:28".to_strftime
&lt;br /&gt;=&gt; "%A %e %B %Y, %H:"
&lt;br /&gt;"Friday 10 July 2009, 20:29".to_strftime
&lt;br /&gt;=&gt; "%A %e %B %Y, %H:%M"
&lt;br /&gt;"Fri 10-07-09 20:30".to_strftime
&lt;br /&gt;=&gt; "%a %e-%m-%y %H:%M"
&lt;br /&gt;"09:25 PM".to_strftime
&lt;br /&gt;=&gt; "%I:%M %p"
&lt;br /&gt;
&lt;br /&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;Resources:
&lt;br /&gt; - &lt;a href="http://snippets.dzone.com/posts/show/2255"&gt;Date Time Format in RUBY&lt;/a&gt; [dzone.com]
&lt;br /&gt; - &lt;a href="http://rorbuilder.info/r/datetime.xml"&gt;datetime.xml&lt;/a&gt; [rorbuilder.info]
&lt;br /&gt;
&lt;br /&gt;*update @ 11-Jul-09 14:51*
&lt;br /&gt;&lt;pre&gt;
&lt;br /&gt;alias dfh='rcscript //job:date_format_helper http://rorbuilder.info/r/datetime.rsf'
&lt;br /&gt;dfh '2009 July 11 Saturday'
&lt;br /&gt;#=&gt; %Y %B %e %A
&lt;br /&gt;&lt;/pre&gt;&lt;img src="http://feeds.feedburner.com/~r/dzone/snippets/~4/GCKwkIJIlII" height="1" width="1"/&gt;</description>
      <pubDate>Fri, 10 Jul 2009 20:28:55 GMT</pubDate>
      <guid isPermaLink="false">http://snippets.dzone.com/posts/show/7579</guid>
      <author>jrobertson (James Robertson)</author>
    <feedburner:origLink>http://snippets.dzone.com/posts/show/7579</feedburner:origLink></item>
    <item>
      <title>Format a date like 1st, 2nd, 3rd</title>
      <link>http://feeds.dzone.com/~r/dzone/snippets/~3/wv0EyhnV_5c/7578</link>
      <description>Source: &lt;a href="http://snippets.dzone.com/posts/show/593"&gt;Helper to print numbers as ordinals (1st, 2nd, 3rd...)&lt;/a&gt; [dzone.com]
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;
&lt;br /&gt;class Numeric
&lt;br /&gt;  def ordinal
&lt;br /&gt;    self.to_s + ( (10...20).include?(self) ? 'th' : %w{ th st nd rd th th th th th th }[self % 10] )
&lt;br /&gt;  end
&lt;br /&gt;end
&lt;br /&gt;&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;
&lt;br /&gt;d = Time.now.day
&lt;br /&gt;puts 'today is the ' + d.ordinal
&lt;br /&gt;#=&gt; today is the 10th
&lt;br /&gt;&lt;/code&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/dzone/snippets/~4/wv0EyhnV_5c" height="1" width="1"/&gt;</description>
      <pubDate>Fri, 10 Jul 2009 16:33:05 GMT</pubDate>
      <guid isPermaLink="false">http://snippets.dzone.com/posts/show/7578</guid>
      <author>jrobertson (James Robertson)</author>
    <feedburner:origLink>http://snippets.dzone.com/posts/show/7578</feedburner:origLink></item>
    <item>
      <title>extract bounding box from a planet file</title>
      <link>http://feeds.dzone.com/~r/dzone/snippets/~3/h9HGq997t1k/7577</link>
      <description>nothing fancy
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;
&lt;br /&gt;osmosis --read-xml file=planet.osm --bounding-box left=$left bottom=$bottom right=$right top=$top --write-xml file=bbox.osm
&lt;br /&gt;&lt;/code&gt;&lt;img src="http://feeds.feedburner.com/~r/dzone/snippets/~4/h9HGq997t1k" height="1" width="1"/&gt;</description>
      <pubDate>Fri, 10 Jul 2009 15:01:37 GMT</pubDate>
      <guid isPermaLink="false">http://snippets.dzone.com/posts/show/7577</guid>
      <author>roondi (ondi.ro)</author>
    <feedburner:origLink>http://snippets.dzone.com/posts/show/7577</feedburner:origLink></item>
    <item>
      <title>Sql server date in format YYYYMMDD</title>
      <link>http://feeds.dzone.com/~r/dzone/snippets/~3/UWx_JujiRqE/7576</link>
      <description>date in YYYYMMDD which is a string 8 CHARACTERS LONG
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;
&lt;br /&gt;SELECT CONVERT(VARCHAR(8), GETDATE(), 112);
&lt;br /&gt;&lt;/code&gt;&lt;img src="http://feeds.feedburner.com/~r/dzone/snippets/~4/UWx_JujiRqE" height="1" width="1"/&gt;</description>
      <pubDate>Fri, 10 Jul 2009 06:36:13 GMT</pubDate>
      <guid isPermaLink="false">http://snippets.dzone.com/posts/show/7576</guid>
      <author>deostroll (Arun Jayapal)</author>
    <feedburner:origLink>http://snippets.dzone.com/posts/show/7576</feedburner:origLink></item>
    <item>
      <title>fixed 定位在 IE6 下的实现技巧一则</title>
      <link>http://feeds.dzone.com/~r/dzone/snippets/~3/T4ECJt4dVyA/7575</link>
      <description>// 1. position: absolute的元素，直接放在position:static的 body 中时，绝对定位的参考物是 body 的 viewport 部分。这使得元素 a 在窗口 resize 时，自动就能准确定位到右下角。注意：body 的 position 不能为 relative 等值，否则失效。
&lt;br /&gt;// 2. onscroll 时需要特殊处理一下，使得滚动时，也让绝对定位元素 a 的参考物能更新为当前的 viewport. 上面的a.className = a.className就是这样一个 hack: 使得 a 的定位参考物动态更新为当前的 viewport. 类似的 hack 还有a.style.background = 'red'. 这些 hack 会引发 reflow, 但反之不一定，进一步的规律没找到，不过有一个 hack，也就够用了。
&lt;br /&gt;
&lt;br /&gt;&lt;code&gt;
&lt;br /&gt;&lt;div id="a" style="width: 300px; height: 100px; background: red"&gt;test&lt;/div&gt;
&lt;br /&gt;&lt;script&gt;
&lt;br /&gt;    var ie6 = !window.XMLHttpRequest;
&lt;br /&gt;
&lt;br /&gt;    var a = document.getElementById('a');
&lt;br /&gt;    a.style.position = ie6 ? 'absolute' : 'fixed';
&lt;br /&gt;    a.style.right = 0;
&lt;br /&gt;    a.style.bottom = 0;
&lt;br /&gt;
&lt;br /&gt;    if (ie6) {
&lt;br /&gt;        window.onscroll = function() {
&lt;br /&gt;            a.className = a.className;
&lt;br /&gt;        };
&lt;br /&gt;    }
&lt;br /&gt;&lt;/script&gt;
&lt;br /&gt;&lt;/code&gt;&lt;img src="http://feeds.feedburner.com/~r/dzone/snippets/~4/T4ECJt4dVyA" height="1" width="1"/&gt;</description>
      <pubDate>Fri, 10 Jul 2009 02:07:42 GMT</pubDate>
      <guid isPermaLink="false">http://snippets.dzone.com/posts/show/7575</guid>
      <author>lotreal (lot)</author>
    <feedburner:origLink>http://snippets.dzone.com/posts/show/7575</feedburner:origLink></item>
    <item>
      <title>Chaos Game with Python</title>
      <link>http://feeds.dzone.com/~r/dzone/snippets/~3/13luwLJLUmM/7574</link>
      <description>&lt;code&gt;
&lt;br /&gt;# 1) Pick three points A,B,C on a plane.
&lt;br /&gt;# 2) Choose a random point D
&lt;br /&gt;# 3) Roll a three-sided and if 1 is rolled draw another point E at the midpoint of A and D. 
&lt;br /&gt;#     Given by ( [Ax+Dx]/2, [Ay+Dy]/2 ), or if two is rolled draw a point at the midpoint between 
&lt;br /&gt;#     B and D, or if 3 is rolled draw a point between C and D.
&lt;br /&gt;# 4) Repeat step 3 except using the new point E instead of point D.
&lt;br /&gt;
&lt;br /&gt;# See http://mathworld.wolfram.com/ChaosGame.html for more info.
&lt;br /&gt;# See http://i12.photobucket.com/albums/a237/Freyrs/100000.png for example output.
&lt;br /&gt;
&lt;br /&gt;from random import random,randint
&lt;br /&gt;from pyx import *
&lt;br /&gt;from math import *
&lt;br /&gt;
&lt;br /&gt;#This will generate a Sierpinski triangle.
&lt;br /&gt;n=3
&lt;br /&gt;r=0.5
&lt;br /&gt;iters = 50000
&lt;br /&gt;
&lt;br /&gt;#Canvas size
&lt;br /&gt;size_x = 200
&lt;br /&gt;size_y = 200
&lt;br /&gt;
&lt;br /&gt;radius = 0.01
&lt;br /&gt;points = []
&lt;br /&gt;c = canvas.canvas()
&lt;br /&gt;
&lt;br /&gt;#Equilateral triangle - any arrangement will work
&lt;br /&gt;points.append((size_x/2,size_y/3))
&lt;br /&gt;points.append((size_x/3,size_y*2/3))
&lt;br /&gt;points.append((size_x*2/3,size_y*2/3))
&lt;br /&gt;
&lt;br /&gt;#Draw random points
&lt;br /&gt;for i in range(1,iters):
&lt;br /&gt;	if i == 1:
&lt;br /&gt;		x_0,y_0 = random()*size_x,random()*size_y
&lt;br /&gt;	#Pick one of the initial points
&lt;br /&gt;	p = randint(0,n-1)
&lt;br /&gt;	x_0,y_0 = (x_0 + points[p][0])*r,(y_0 + points[p][1])*r
&lt;br /&gt;	c.fill(path.circle(x_0,y_0, radius))
&lt;br /&gt;
&lt;br /&gt;d = document.document(pages = [document.page(c, paperformat=document.paperformat.A4, fittosize=1)])
&lt;br /&gt;d.writePSfile("chaos_game.ps")
&lt;br /&gt;&lt;/code&gt;&lt;img src="http://feeds.feedburner.com/~r/dzone/snippets/~4/13luwLJLUmM" height="1" width="1"/&gt;</description>
      <pubDate>Thu, 09 Jul 2009 21:00:38 GMT</pubDate>
      <guid isPermaLink="false">http://snippets.dzone.com/posts/show/7574</guid>
      <author>sdiehl (Steve D.)</author>
    <feedburner:origLink>http://snippets.dzone.com/posts/show/7574</feedburner:origLink></item>
  </channel>
</rss>
