<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: cloud code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 03:04:15 GMT</pubDate>
    <description>DZone Snippets: cloud code</description>
    <item>
      <title>Tag Cloud in Ruby</title>
      <link>http://snippets.dzone.com/posts/show/2251</link>
      <description>The options.delete with the default looks mildly interesting. Just wanted to remember that.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;def font_size_for_tag_cloud( total, lowest, highest, options={} )&lt;br /&gt; return nil if total.nil? or highest.nil? or lowest.nil?&lt;br /&gt; #&lt;br /&gt; # options&lt;br /&gt; maxf = options.delete( :max_font_size ) || 14&lt;br /&gt; minf = options.delete( :min_font_size ) || 11&lt;br /&gt; maxc = options.delete( :max_color ) || [ 0, 0, 0 ]&lt;br /&gt; minc = options.delete( :min_color ) || [ 156, 156, 156 ]&lt;br /&gt; hide_sizes = options.delete( :hide_sizes )&lt;br /&gt; hide_colours = options.delete( :hide_colours )&lt;br /&gt; #&lt;br /&gt; # function to work out rgb values&lt;br /&gt; def rgb_color( a, b, i, x)&lt;br /&gt;  return nil if i &lt;= 1 or x &lt;= 1&lt;br /&gt;  if a &gt; b&lt;br /&gt;   a-(Math.log(i)*(a-b)/Math.log(x)).floor&lt;br /&gt;  else&lt;br /&gt;   (Math.log(i)*(b-a)/Math.log(x)+a).floor&lt;br /&gt;  end&lt;br /&gt; end&lt;br /&gt; #&lt;br /&gt; # work out colours&lt;br /&gt; c = []&lt;br /&gt; (0..2).each { |i| c &lt;&lt; rgb_color( minc[i], maxc[i], total, highest ) || nil }&lt;br /&gt; colors = c.compact.empty? ? minc.join(',') : c.join(',')&lt;br /&gt; #&lt;br /&gt; # work out the font size&lt;br /&gt; spread = highest.to_f - lowest.to_f&lt;br /&gt; spread = 1.to_f if spread &lt;= 0&lt;br /&gt; fontspread = maxf.to_f - minf.to_f&lt;br /&gt; fontstep = spread / fontspread&lt;br /&gt; size = ( minf + ( total.to_f / fontstep ) ).to_i&lt;br /&gt; size = maxf if size &gt; maxf&lt;br /&gt; #&lt;br /&gt; # display the results&lt;br /&gt; size_txt = "font-size:#{ size.to_s }px;" unless hide_sizes&lt;br /&gt; color_txt = "color:rgb(#{ colors });" unless hide_colours&lt;br /&gt; return [ size_txt, color_txt ].join&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 06 Jul 2006 17:01:58 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2251</guid>
      <author>jnunemaker ()</author>
    </item>
    <item>
      <title>Tag cloud using Text()</title>
      <link>http://snippets.dzone.com/posts/show/1658</link>
      <description>&lt;br /&gt;&lt;code&gt;&lt;br /&gt;from appuifw import *&lt;br /&gt;app.body = t = Text()&lt;br /&gt;&lt;br /&gt;fonts = [u'', u'LatinPlain12', u'LatinBold12', u'LatinBold13', u'LatinBold17', u'LatinBold19']&lt;br /&gt;tags = [(1, "apache"), (1, "array"), (1, "bash"), (1, "c"), (1, "cli"), (1, "csharp"), (1, "css"),&lt;br /&gt;  (1, "database"), (1, "date"), (1, "expressionengine"), (1, "file"), (2, "html"), (1, "image"),&lt;br /&gt;  (2, "java"), (4, "javascript"), (1, "lighttpd"), (1, "linux"), (1, "mac"), (1, "math"), (1, "mysql"),&lt;br /&gt;  (1, "osx"), (1, "perl"), (3, "php"), (1, "pys60"), (5, "python"), (4, "rails"), (1, "regex"),&lt;br /&gt; (4, "ruby"), (1, "rubyonrails"), (1, "series"), (3, "series60"), (1, "servers"), (2, "shell"), (2, "sql"),&lt;br /&gt; (1, "ssh"), (1, "string"), (1, "text"), (1, "time"), (1, "unix"), (1, "web"), (1, "windows"), (1, "xml"),]&lt;br /&gt;&lt;br /&gt;for level, tag in tags:&lt;br /&gt;    t.font = fonts[level]&lt;br /&gt;    t.add(tag + u' ')&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;See &lt;a href=http://www.frappr.com/pys60/photo/1514489&gt;screenshot&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;If using font is not enough, we can use other styles or colors.&lt;br /&gt;See a &lt;a href=http://bigbold.com/snippets/posts/show/1612&gt;related snippet&lt;/a&gt;.</description>
      <pubDate>Wed, 08 Mar 2006 15:57:17 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1658</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
