Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

View all colors from a set of stylesheets

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.

BROWSER = "/Applications/Safari.app/Contents/MacOS/Safari"
CSS_FILES = "#{RAILS_ROOT}/public/stylesheets/**/*.css"

task :colors do
  require "tempfile"
  colors = Dir[CSS_FILES].map(&File.method(:read)).join.scan(/\#[0-9a-f]{3,6}/i).map{|c| c.upcase}.uniq
  Tempfile.open "colors" do |f|
    f.write <<-EOHTML
    <html>
      <head>
        <style type="text/css">
          div { width: 50px; height: 50px; display: inline-block }
        </style>
      </head>
      <body>
        #{colors.map{|clr| 
          "<div style='background: #{clr}'>&nbsp;</div> #{clr} <br />"
        }.join}
      </body>
    </html>
    EOHTML
    system BROWSER, f.path
  end
end

Alternating table colors for rows and columns.

This code will provide 8 colors for cells and set of 8 lighter colors for alternating rows.
<?php
$sql  = 'SELECT * FROM `table` WHERE `column` = \'something\'';
$qry = mysql_query($sql) or die(mysql_error());

// Cell colors for odd rows
$c1  = array('#00CCCC', '#33CC00', '#CC0000', '#CCCC00', '#0000CC', '#FF6600', '#CC00CC', '#00CC99');

// Cell Colors for even rows
$c2  = array('#66FFFF', '#66FF00', '#FF3300', '#FFFF33', '#0033FF', '#FF9933', '#FF33CC', '#00FF99');

// Row Counter
$cnt  = 0;

$ret = '<table>';
while($row = mysql_fetch_assoc($qry))
{
  // Cell counter
  $cnt2 = 0;
  $ret  .= '<tr>';
  foreach($row as $key=>$val)
   {
    $ret .= '<td bgcolor="';

    if($cnt % 2)
      {
        $ret .= $c1[$cnt2];
      }
    else
      {
        $ret .= $c2[$cnt2];
      }

    $ret .= '">'.$val.'</td>';
    ++$cnt2;
   }
  ++$cnt;
  $ret .= '</tr>'."\n";
}
$ret .= '</table>';

echo $ret;
?> 
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS