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

About this user

Peter Cooperx http://www.petercooper.co.uk/

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

Generic XHTML template

I'm often having to reconstruct this, as I can no longer memorize everything (just blank HTML and BODY tags used to be acceptable ;-)) with the DOCTYPE and namespaces.. so to make it easier to grab in future:

   1  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   2         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   3  
   4  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
   5  	<head>
   6  		<title></title>
   7  		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   8  		<link rel="stylesheet" href="styles.css" type="text/css" media="screen" />
   9  		<script type="text/javascript" src="common.js"></script>
  10  	</head>
  11  
  12  	<body>
  13  		<div id="container">
  14  
  15  			<div id="header">
  16  			</div>
  17  
  18  			<div id="wrapper">
  19  				<div id="main">
  20  					
  21  				</div>
  22  			</div>
  23  
  24  			<div id="footer">
  25  			</div>
  26  			
  27  		</div>
  28  	</body>
  29  
  30  </html>

Parse HTML files as PHP

Add this to your .htaccess file in Apache:

   1  AddType application/x-httpd-php .html

Turn off image buttons / icons on your pages in IE

Turn off the image buttons (when you hover over an image) and Smart Tags in IE:

   1  <meta http-equiv="imagetoolbar" content="false" />
   2  <meta name="MSSmartTagsPreventParsing" content="true" />

Close forgotten HTML tags easily in user HTML input

If you let users type raw HTML into your input boxes, they will inevitably forget to close some of their tags from time to time. Close any forgotten tags with this:

   1  h1 = {}
   2  h2 = {}
   3  code.scan(/\<([^\>\s\/]+)[^\>\/]*?\>/).each { |t| h1[t[0]] ? h1[t[0]] += 1 : h1[t[0]] = 1 }
   4  code.scan(/\<\/([^\>\s\/]+)[^\>]*?\>/).each { |t| h2[t[0]] ? h2[t[0]] += 1 : h2[t[0]] = 1 }
   5  h1.each {|k,v| code += "</#{k}>" * (h1[k] - h2[k].to_i) if h2[k].to_i < v }

creating a select box on a table's contents

   1  <%= select('user', 'sites', Site.find_all.collect  {|site| site.name}) %>
« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS