<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Colors code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 07:29:46 GMT</pubDate>
    <description>DZone Snippets: Colors code</description>
    <item>
      <title>View all colors from a set of stylesheets</title>
      <link>http://snippets.dzone.com/posts/show/4616</link>
      <description>Rake task to grep out colors from a set of CSS stylesheets and display them on a web page. Default configuration works for OS X Safari and a Rails application.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;BROWSER = "/Applications/Safari.app/Contents/MacOS/Safari"&lt;br /&gt;CSS_FILES = "#{RAILS_ROOT}/public/stylesheets/**/*.css"&lt;br /&gt;&lt;br /&gt;task :colors do&lt;br /&gt;  require "tempfile"&lt;br /&gt;  colors = Dir[CSS_FILES].map(&amp;File.method(:read)).join.scan(/\#[0-9a-f]{3,6}/i).map{|c| c.upcase}.uniq&lt;br /&gt;  Tempfile.open "colors" do |f|&lt;br /&gt;    f.write &lt;&lt;-EOHTML&lt;br /&gt;    &lt;html&gt;&lt;br /&gt;      &lt;head&gt;&lt;br /&gt;        &lt;style type="text/css"&gt;&lt;br /&gt;          div { width: 50px; height: 50px; display: inline-block }&lt;br /&gt;        &lt;/style&gt;&lt;br /&gt;      &lt;/head&gt;&lt;br /&gt;      &lt;body&gt;&lt;br /&gt;        #{colors.map{|clr| &lt;br /&gt;          "&lt;div style='background: #{clr}'&gt;&amp;nbsp;&lt;/div&gt; #{clr} &lt;br /&gt;"&lt;br /&gt;        }.join}&lt;br /&gt;      &lt;/body&gt;&lt;br /&gt;    &lt;/html&gt;&lt;br /&gt;    EOHTML&lt;br /&gt;    system BROWSER, f.path&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 04 Oct 2007 17:19:13 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4616</guid>
      <author>bradediger (Brad Ediger)</author>
    </item>
    <item>
      <title>Alternating table colors for rows and columns.</title>
      <link>http://snippets.dzone.com/posts/show/4410</link>
      <description>This code will provide 8 colors for cells and set of 8 lighter colors for alternating rows.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;$sql  = 'SELECT * FROM `table` WHERE `column` = \'something\'';&lt;br /&gt;$qry = mysql_query($sql) or die(mysql_error());&lt;br /&gt;&lt;br /&gt;// Cell colors for odd rows&lt;br /&gt;$c1  = array('#00CCCC', '#33CC00', '#CC0000', '#CCCC00', '#0000CC', '#FF6600', '#CC00CC', '#00CC99');&lt;br /&gt;&lt;br /&gt;// Cell Colors for even rows&lt;br /&gt;$c2  = array('#66FFFF', '#66FF00', '#FF3300', '#FFFF33', '#0033FF', '#FF9933', '#FF33CC', '#00FF99');&lt;br /&gt;&lt;br /&gt;// Row Counter&lt;br /&gt;$cnt  = 0;&lt;br /&gt;&lt;br /&gt;$ret = '&lt;table&gt;';&lt;br /&gt;while($row = mysql_fetch_assoc($qry))&lt;br /&gt;{&lt;br /&gt;  // Cell counter&lt;br /&gt;  $cnt2 = 0;&lt;br /&gt;  $ret  .= '&lt;tr&gt;';&lt;br /&gt;  foreach($row as $key=&gt;$val)&lt;br /&gt;   {&lt;br /&gt;    $ret .= '&lt;td bgcolor="';&lt;br /&gt;&lt;br /&gt;    if($cnt % 2)&lt;br /&gt;      {&lt;br /&gt;        $ret .= $c1[$cnt2];&lt;br /&gt;      }&lt;br /&gt;    else&lt;br /&gt;      {&lt;br /&gt;        $ret .= $c2[$cnt2];&lt;br /&gt;      }&lt;br /&gt;&lt;br /&gt;    $ret .= '"&gt;'.$val.'&lt;/td&gt;';&lt;br /&gt;    ++$cnt2;&lt;br /&gt;   }&lt;br /&gt;  ++$cnt;&lt;br /&gt;  $ret .= '&lt;/tr&gt;'."\n";&lt;br /&gt;}&lt;br /&gt;$ret .= '&lt;/table&gt;';&lt;br /&gt;&lt;br /&gt;echo $ret;&lt;br /&gt;?&gt; &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 10 Aug 2007 16:59:53 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4410</guid>
      <author>ellisgl (Kenneth Ellis McCall)</author>
    </item>
  </channel>
</rss>
