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

[ruby] plugin structure

plugin structure sorta thing. Use inherited to concatenate all plugins to a library in a Plugins constant in said library.

class Library
  Plugins = []
  
  def initialize#(...)
    Plugins.each do |plugin|
      # Here you can run a certain class method or grab some data from each class
    end
  end
  
  # ...
end


class LibraryPlugin
  # ...
  
  def self.inherited(sub); Library::Plugins << sub; end
end


class LibraryFooer < LibraryPlugin
  
end
class LibraryBarer < LibraryPlugin
  
end


Library::Plugins.inspect #=> [LibraryFooer, LibraryBarer]

Include text files in C source

This includes the contents of myfile.txt into the char array text.

Note: This only works if ALL lines in the file are enclosed in "s.

Wrong myfile.txt:
Hello world
Goodbye world



Right myfile.txt:
"Hello world"
"Goodbyle world"
""

char text[] = {
#include "myfile.txt"
}

Include javascript by DOM

Orignial: http://www.codepost.org/browse/snippets/85

function include(file)
{
      var script  = document.createElement('script');
      script.src  = file;
      script.type = 'text/javascript';

      document.getElementsByTagName('head').item(0).appendChild(script);
}

Include javascript by XMLHttpRequest

Original from http://www.exit12.org/archives/12
function include(jsFileLocation)
{
	if(window.XMLHttpRequest)
	{
		var req = new XMLHttpRequest();
	}
	else
	{
		var req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.open("GET", jsFileLocation,false);
	req.onreadystatechange = function()
	{
		if (req.readyState == 4)
		{
			window.eval(req.responseText);
		}
	}
	req.send(null);
}

Splitting large Scriptella ETL files

The following example demonstrates how to split a large Scriptella ETL file into several parts. This example is based on a traditional XML parsed entities approach:

<!DOCTYPE etl SYSTEM "http://scriptella.javaforge.com/dtd/etl.dtd"
[
    <!-- Declaring the first external parsed entity to include -->
    <!ENTITY part1 SYSTEM "part1.xml">
    
    <!-- Declaring the second external parsed entity to include -->
    <!ENTITY part2 SYSTEM "part2.xml">
]>
<etl>
    <connection driver="text"/>

    <!-- Including file #1 -->
    &part1;

    <script>
        content of the script
    </script>
    
    <!-- Including file #2 -->
    &part2;

</etl>
« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS