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-3 of 3 total  RSS 

ISO 8601 date format for microformats

Used this in Ruby to get the ISO 8601 (see RFC 3339) full date format for an hEvent Microformat. Doubtless usable in other situations.

strftime('%Y-%m-%dT%H:%M:%S%z')


How to use:

<abbr class="dtstart" title="<%= event.start_date.strftime('%Y-%m-%dT%H:%M:%S%z') %>"><%= event.start_date.to_s(:long) %></abbr>

hCard to JSON bridge

// Requires http://pear.php.net/pepr/pepr-proposal-show.php?id=198 and http://allinthehead.com/hkit
// Many thanks to the authors of these libraries and to the microformats community.
// Demo: http://simplelogica.net/cajondesastre/hcard2json/index.php?url=http://11870.com/pro/19483
// Manuel González Noriega for Simplelógica. Hire us at http://simplelogica.net


    include('hkit.class.php');
    include('JSON.class.php');
		
    $debug = true;
		
    $status = '200';
    $ct = 'text/plain';
		
    $hKit = new hKit;
    $json = new Services_JSON();

    if ($_GET['url']) {
      $result = $hKit->getByURL('hcard', $_GET['url']);
	    
      if ($result) {
	$o = ($json->encode($result));
	$ct = ($debug) ? 'text/plain' : 'application/json';			
      }
      else {
	$o = '404 Not Found';
	$status = '404';
      }
    }
    else {
      $o = '400 Bad Request';
      $status = '400';
    }
	
 

  header('Content-type: '.$ct);
  
  switch($status) {
    case '400':
      header("HTTP/1.0 400 Bad Request");
    break;
	
    case '404':
      header("HTTP/1.0 404 Not Found");
    break;

    case '200':
    default:
      header("HTTP/1.0 200 OK");
    break;
}

print $o;

Mofo - Parse Microformats with Ruby

$ sudo gem install mofo 
Successfully installed mofo-0.2.1
$ irb -rubygems
>> require 'mofo'
=> true
>> HResume.find("http://resume.jnewland.com").tags.uniq.sort
=> ["AJAX", "Apache", "CSS", "Capistrano", "DNS", "GNU/Linux", "HTML", "Javascript", "LAMP", "Mongrel", "Movable Type", "MySQL", "PHP", "Perl", "REST", "RSS", "Ruby", "Ruby on Rails", "SEO", "XHTML", "XML", "XSLT", "high availability", "lighttpd", "load-balanced"]
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS