This page has the following setup.
Do you want to know how many spans have been generated by Chili?
Click on a language below to show / hide the code.
/*
===============================================================================
Metaobjects is the metadata plugin on steroids
...............................................................................
Copyright 2007 / Andrea Ercolino
-------------------------------------------------------------------------------
LICENSE: http://www.opensource.org/licenses/mit-license.php
WEBSITE: http://noteslog.com/metaobjects/
===============================================================================
*/
( function($) {
$.metaobjects = function( options ) {
options = $.extend( {
context: document
, clean: true
, selector: 'object.metaobject'
}, options );
function jsValue( value ) {
eval( 'value = ' + value + ";" );
return value;
}
return $( options.selector, options.context )
.each( function() {
var settings = { target: this.parentNode };
$( '> param[@name=metaparam]', this )
.each( function() {
$.extend( settings, jsValue( this.value ) );
} );
$( '> param', this )
.not( '[@name=metaparam]' )
.each( function() {
var name = this.name, value = jsValue( this.value );
$( settings.target )
.each( function() {
this[ name ] = value;
} );
} );
if( options.clean ) {
$( this ).remove();
}
} );
};
} ) ( jQuery );
/*
Plugin Name: Enzymes
Plugin URI: http://mondotondo.com/aercolino/noteslog/?cat=9
Description: The Enzymes WordPress plugin let's you EFFORTLESSLY metabolize (transclude / execute)
custom fields inside a post, a page, and everywhere in a theme. You need Enzymes.
Author: Andrea Ercolino
Version: 1.2
Author URI: http://mondotondo.com/aercolino/noteslog
*/
class Enzymes {
var $content = ''; // the content of the post, modified by Enzymes
var $post = ''; // the post which the content belongs to
var $product = ''; // the output of the pathway
var $substrate = ''; // a custom field passed as additional input to an enzyme
var $result = ''; // the output of the enzyme
var $e; // array of patterns of regular expressions
var $quote = '='; // the quote used for fields (texturize safe and single char)
function Enzymes() {
//basic expressions
$this->e = array(
'post' => '\d*'
, 'quoted' => $this->quote.'[^'.$this->quote.'\\\\]*'
.'(?:\\\\.[^'.$this->quote.'\\\\]*)*'.$this->quote
, 'oneword' => '[\w\-]+'
, 'star' => '\*'
, 'template' => '(?:(?P<tempType>\/|\\\\)(?P<template>(?:[^\|])+))'
, 'comment' => '(?P<comment>\/\*.*?\*\/)'
, 'rest' => '(?:\|(?P<rest>.+))'
, 'before' => '(?P<before>.*?)'
, 'statement' => '\{\[(?P<statement>.*?)\]\}'
, 'after' => '(?P<after>.*)'
);
//complex expressions
$this->e['content'] =
'^'.$this->e['before'].$this->e['statement'].$this->e['after'].'$';
$this->e['field'] = // this is used twice, so cannot have names for its pieces
$this->e['quoted'].'|'.$this->e['oneword'].'|'.$this->e['star'];
$this->e['enzyme'] =
'(?P<enzymePost>'.$this->e['post'].')\.(?P<enzymeField>'.$this->e['field'].')';
$this->e['substrate'] =
'(?P<substratePost>'.$this->e['post'].')\.(?P<substrateField>'.$this->e['field'].')';
$this->e['subBlock'] =
'(?P<subBlock>\((?:'.$this->e['substrate'].')?\))';
$this->e['block'] =
$this->e['enzyme'].$this->e['subBlock'].'?'.$this->e['template'].'?';
// X = block|block|...|block
// if processing X, match /block|rest*/ against X
$this->e['pathway'] =
'^'.$this->e['block'].$this->e['rest'].'?$';
// if admitting X, match /(|head)+/ against |X
$this->e['pathway2'] =
'^(?:\|'.$this->e['block'].')+$';
}
function apply_template( $template ) {
if( '' != $template ) {
$file_path = ABSPATH . '/wp-content/' . $template;
if( file_exists( $file_path ) ) {
ob_start();
include( $file_path ); // include the requested template in the local scope
$this->result = ob_get_contents();
ob_end_clean();
}
}
}
function apply_enzyme( $enzyme ) {
if( $this->post )
$post = $this->post;
else
global $post;
if( '' != $enzyme ) {
ob_start();
eval( $enzyme ); // evaluate the requested enzyme in the local scope
$this->result = ob_get_contents();
ob_end_clean();
}
}
function item( $id, $key ) {
if( $this->post )
$post = $this->post;
else
global $post;
if( '' == $key ) return '';
if( '*' == $key ) {
if( '' == $id ) return $post->post_content;
$a_post = get_post( $id );
return $a_post->post_content;
}
if( '' == $id ) $id = $post->ID;
if( preg_match( '/'.$this->e['quoted'].'/', $key ) ) {
// unwrap from quotes
$key = substr( $key, 1, -1 );
// unescape escaped quotes
$key = preg_replace( '/\\\\'.$this->quote.'/', $this->quote, $key );
}
return get_post_meta( $id, $key, true );
}
function catalyze( $matches ) {
$enzyme = $this->item( $matches['enzymePost'], $matches['enzymeField'] );
if( '' == $matches['subBlock'] ) {
// transclusion
$this->substrate = '';
$this->result = $enzyme;
if( '' != $matches['template'] ) {
if( '/' == $matches['tempType'] ) {
// slash template
$this->result = $this->product . $this->result;
$this->apply_template( $matches['template'] );
}
else {
// backslash template
$this->apply_template( $matches['template'] );
$this->result = $this->product . $this->result;
}
}
else {
$this->result = $this->product . $this->result;
}
}
else {
// execution
$this->substrate = $this->item( $matches['substratePost'], $matches['substrateField'] );
if( $enzyme ) $this->apply_enzyme( $enzyme );
else $this->result = '';
$this->apply_template( $matches['template'] );
if( '' != $matches['template'] ) {
if( '/' == $matches['tempType'] ) {
// slash template
}
else {
// backslash template
$this->result = $this->product . $this->result;
}
}
}
$this->product = $this->result;
}
function cb_strip_blanks( $matches ) {
// I suspect the $matches array is a copy without names
$before = $matches[1];
$quoted = $matches[2];
$after = $matches[3];
$blanks = '/(?:\s|\n)+/';
if( '' != $quoted ) {
return preg_replace( $blanks, '', $before ) . $quoted;
}
else {
return preg_replace( $blanks, '', $after );
}
}
function metabolism( $content, $post = '' ) {
if( ! preg_match( '/'.$this->e['content'].'/s', $content, $matchesOut ) ) return $content;
else {
$this->content = '';
$this->post = $post;
do {
if( '{' == substr( $matchesOut['before'], -1 ) ) { //not to be processed
$result = '['.$matchesOut['statement'].']}';
}
else {
// erase tags
$sttmnt = strip_tags( $matchesOut['statement'] );
// erase blanks (except inside quoted strings)
$sttmnt = preg_replace_callback(
'/(.*?)('.$this->e['quoted'].')|(.+)/s', array( $this, 'cb_strip_blanks' ), $sttmnt
);
// erase comments
$sttmnt = preg_replace( '/'.$this->e['comment'].'/', '', $sttmnt );
if( ! preg_match( '/'.$this->e['pathway2'].'/', '|'.$sttmnt ) ) { //not a pathway
$result = '{['.$matchesOut['statement'].']}';
}
else { // process statement
$this->product = '';
$matchesIn['rest'] = $sttmnt;
while( preg_match( '/'.$this->e['pathway'].'/', $matchesIn['rest'], $matchesIn ) ) {
$this->catalyze( $matchesIn );
}
$result = $this->product;
}
}
$this->content .= $matchesOut['before'].$result;
$after = $matchesOut['after']; // save tail, if next match fails
}
while( preg_match( '/'.$this->e['content'].'/s', $matchesOut['after'], $matchesOut ) );
return $this->content.$after;
}
}
// these functions only send a simple log to my server on plugin activation / deactivation
function makeURL( $mode ) {
return 'http://mondotondo.com/aercolino/count/enzymes/1.2/'.$mode.'/empty.txt';
}
function activate() {
$fh = fopen( $this->makeURL( 'activate' ), 'r' );
if( false !== $fh ) fclose( $fh );
}
function deactivate() {
$fh = fopen( $this->makeURL( 'deactivate' ), 'r' );
if( false !== $fh ) fclose( $fh );
}
}
$enzymes = new Enzymes();
add_filter( 'wp_title', array( &$enzymes, 'metabolism' ), 10, 2 );
add_filter( 'the_title', array( &$enzymes, 'metabolism' ), 10, 2 );
add_filter( 'the_title_rss', array( &$enzymes, 'metabolism' ), 10, 2 );
add_filter( 'the_excerpt', array( &$enzymes, 'metabolism' ), 10, 2 );
add_filter( 'the_excerpt_rss', array( &$enzymes, 'metabolism' ), 10, 2 );
add_filter( 'the_content', array( &$enzymes, 'metabolism' ), 10, 2 );
function metabolize( $content, $post = '' ) {
global $enzymes;
echo $enzymes->metabolism( $content, $post );
}
add_action( 'activate_enzymes/enzymes-1.2.php', array( &$enzymes, 'activate' ) );
add_action( 'deactivate_enzymes/enzymes-1.2.php', array( &$enzymes, 'deactivate' ) );
/*
extracted from "Advanced MySQL user variable techniques"
(http://www.xaprb.com/blog/2006/12/15/advanced-mysql-user-variable-techniques/)
*/
CREATE TABLE fruits (
`type` varchar(10) NOT NULL,
variety varchar(20) NOT NULL,
price decimal(5,2) NOT NULL default 0,
PRIMARY KEY (`type`,variety)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
insert into fruits(`type`, variety, price) values
('apple', 'gala', 2.79),
('apple', 'fuji', 0.24),
('apple', 'limbertwig', 2.87),
('orange', 'valencia', 3.59),
('orange', 'navel', 9.36),
('pear', 'bradford', 6.05),
('pear', 'bartlett', 2.14),
('cherry', 'bing', 2.55),
('cherry', 'chelan', 6.33);
set @num := 0, @type := '';
select `type`, variety, price, @num
from fruits
where 2 >= greatest(
@num := if(@type = `type`, @num + 1, 1),
least(0, length(@type := `type`)));
<!--
extracted from "HTML 4.01 Entities Reference"
(http://www.w3schools.com/tags/ref_entities.asp)
-->
<hr />
<h2>ASCII Entities with new Entity Names</h2>
<table class="ex" cellspacing="0" border="1" width="100%">
<tr>
<th align="left">Result</th>
<th align="left">Description</th>
<th align="left">Entity Name</th>
<th align="left">Entity Number</th>
</tr>
<tr>
<td>"</td>
<td>quotation mark</td>
<td>&quot;</td>
<td>&#34;</td>
</tr>
<tr>
<td>'</td>
<td>apostrophe </td>
<td>&apos; (does not work in IE)</td>
<td>&#39;</td>
</tr>
<tr>
<td>&</td>
<td>ampersand</td>
<td>&amp;</td>
<td>&#38;</td>
</tr>
<tr>
<td><</td>
<td>less-than</td>
<td>&lt;</td>
<td>&#60;</td>
</tr>
<tr>
<td>></td>
<td>greater-than</td>
<td>&gt;</td>
<td>&#62;</td>
</tr>
</table>
/*
extracted from "Reference Objects and Garbage Collection"
(http://java.sun.com/developer/technicalArticles/ALT/RefObj/index.html)
*/
import java.awt.Graphics;
import java.awt.Image;
import java.applet.Applet;
import java.lang.ref.SoftReference;
public class DisplayImage extends Applet {
SoftReference sr = null;
public void init() {
System.out.println("Initializing");
}
public void paint(Graphics g) {
Image im = (
sr == null) ? null : (Image)(
sr.get());
if (im == null) {
System.out.println(
"Fetching image");
im = getImage(getCodeBase(),
"truck1.gif");
sr = new SoftReference(im);
}
System.out.println("Painting");
g.drawImage(im, 25, 25, this);
im = null;
/* Clear the strong reference to the image */
}
public void start() {
System.out.println("Starting");
}
public void stop() {
System.out.println("Stopping");
}
}
/*
extracted from "Templates"
(http://www.cplusplus.com/doc/tutorial/templates.html)
*/
// sequence template
#include <iostream>
using namespace std;
template <class T, int N>
class mysequence {
T memblock [N];
public:
void setmember (int x, T value);
T getmember (int x);
};
template <class T, int N>
void mysequence<T,N>::setmember (int x, T value) {
memblock[x]=value;
}
template <class T, int N>
T mysequence<T,N>::getmember (int x) {
return memblock[x];
}
int main () {
mysequence <int,5> myints;
mysequence <double,5> myfloats;
myints.setmember (0,100);
myfloats.setmember (3,3.1416);
cout << myints.getmember(0) << '\n';
cout << myfloats.getmember(3) << '\n';
return 0;
}
/*
extracted from "Introducing Generics in the CLR"
(http://msdn.microsoft.com/msdnmag/issues/03/09/NET/)
*/
using System;
// Definition of a node type for creating a linked list
class Node {
Object m_data;
Node m_next;
public Node(Object data, Node next) {
m_data = data;
m_next = next;
}
// Access the data for the node
public Object Data {
get { return m_data; }
}
// Access the next node
public Node Next {
get { return m_next; }
}
// Get a string representation of the node
public override String ToString() {
return m_data.ToString();
}
}
// Code that uses the node type
class App {
public static void Main() {
// Create a linked list of integers
Node head = new Node(5, null);
head = new Node(10, head);
head = new Node(15, head);
// Sum-up integers by traversing linked list
Int32 sum = 0;
for (Node current = head; current != null;
current = current.Next) {
sum += (Int32) current.Data;
}
// Output sum
Console.WriteLine("Sum of nodes = {0}", sum);
}
}
(*
extracted from "Avoiding memory leaks"
(http://www.delphibasics.co.uk/Article.asp?Name=Memory)
*)
unit MyClass;
interface
uses
Classes;
type
TMyClass = class
private
fileData : TStringList;
published
Constructor Create(const fileName : string);
Destructor Destroy; override;
procedure PrintFile;
end;
implementation
uses
Printers, Dialogs, SysUtils;
// Constructor - builds the class object
constructor TMyClass.Create(const fileName: string);
begin
// Create the string list object used to hold the file contents
fileData := TStringList.Create;
// And load the file data into it
try
fileData.LoadFromFile(fileName);
except
ShowMessage('Error : '+fileName+' file not found.');
end;
end;
// Destructor - frees up memory used by the class object
destructor TMyClass.Destroy;
begin
// Free up the memory used by the string list object
FreeAndNil(fileData);
// Call the parent class destructor
inherited;
end;
// Print the file passed to the constructor
procedure TMyClass.PrintFile;
var
myFile : TextFile;
i : Integer;
begin
// Open a printer file
AssignPrn(myFile);
// Now prepare to write to the printer
ReWrite(myFile);
// Write the lines of the file to the printer
for i := 0 to fileData.Count-1 do
WriteLn(myFile, fileData[i]);
// Close the print file
CloseFile(myFile);
end;
end.
%REM
extracted from "OLE constants"
(http://www.mondotondo.com/aercolino/noteslog/?p=18)
%END REM
'Install tlbinf32.dll:
Option Public
Option Declare
Use "RegistryAccess"
Sub Initialize
%INCLUDE "error_handling"
Dim tli As Variant
On Error Resume Next
Set tli = CreateObject( "TLI.TLIApplication" )
On Error Goto HandleError
If Err = 0 Then
Set tli = Nothing
Exit Sub
End If
Dim instalar As String
instalar = "tlbinf32.dll"
Dim s As New NotesSession
Dim db As NotesDatabase
Set db = s.CurrentDatabase
Dim d As notesdocument
Set d = GetHelpAboutDocument( db, instalar )
If d Is Nothing Then
Msgbox "The library " & instalar & " has not been installed" & Chr( 10 ) _
& "The library could not be found in the database" & Chr( 10 ) _
& "Please notify your admin"
Exit Sub
End If
Dim systemRoot As String
systemRoot = RegQueryValue( "HKEY_LOCAL_MACHINE", "SOFTWAREMicrosoftWindows NTCurrentVersion", "SystemRoot" )
Dim path As String
path = systemRoot & "system32" & instalar
Call ExtractAttachment( d, instalar, path )
If Dir( path ) = "" Then
Msgbox "The library " & instalar & " has not been installed" & Chr( 10 ) _
& "The library could not be put in the folder " & path & Chr( 10 ) _
& "Please notify your admin"
Exit Sub
End If
If Shell( "regsvr32 /s " & instalar ) <> 33 Then
Msgbox "The library " & instalar & " has not been installed" & Chr( 10 ) _
& "The library could not be registered" & Chr( 10 ) _
& "Please notify your admin"
Exit Sub
End If
Msgbox "The library " & instalar & " has been installed"
' HKEY_CLASSES_ROOTCLSID{8B217746-717D-11CE-AB5B-D41203C10000}InprocServer32
End Sub
Function GetHelpAboutDocument( db As NotesDatabase, filename As String ) As NotesDocument
%INCLUDE "error_handling"
Dim nc As NotesNoteCollection
Set nc = db.CreateNoteCollection( False )
nc.SelectHelpAbout = True
Call nc.BuildCollection
Dim nid As String
nid = nc.GetFirstNoteId
If nid <> "" Then
Set GetHelpAboutDocument = db.GetDocumentByID( nid )
Else
Set GetHelpAboutDocument = Nothing
End If
End Function
Sub ExtractAttachment( d As NotesDocument, filename As String, path As String )
%INCLUDE "error_handling"
If Not d.HasEmbedded Then Exit Sub
Dim embedded As NotesEmbeddedObject
Set embedded = d.GetAttachment( filename )
If embedded Is Nothing Then Exit Sub
Call embedded.ExtractFile( path )
End Sub