Skip to content

Instantly share code, notes, and snippets.

@drslump
drslump / AnnotationsLexerGenerator.php
Created August 13, 2009 22:11
A runtime lexer generator which obtains the lexical rules from annotations
<?php
/**
* A runtime lexer generator which obtains the lexical rules from annotations.
*
* Copyright 2009 (c) Iván -DrSlump- Montes <drslump@pollinimini.net>
* Released to the Public Domain
*
* It supports the following annotations:
*
* - @lexer-mode
/*
JSpec module which adds a new formatter (JSpec.formatters.jUnit) to generate an
xml document compatible with Hudson CI jUnit result browser.
(c) 2009 Iván -DrSlump- Montes <drslump _at_ pollinimini.net
Public Domain
*/
JSpec.include({
'formatters': {
<?php
/**
* Wraps an iterator allowing to obtain chunks of it as simple arrays
*
* It mimics the behaviour of the array_chunk() function.
*
* @license Public Domain
* @author Iván -DrSlump- Montes <drslump_at_pollinimini_dot_net>
*/
class ChunkIterator implements Iterator, OuterIterator
Index: include/template.php
===================================================================
--- include/template.php (revision 1176)
+++ include/template.php (working copy)
@@ -256,3 +256,26 @@
}
return $line;
}
+
+
@drslump
drslump / Command.php
Created May 31, 2010 20:49
PHP Command runner class
<?php
/**
* Command building and execution
*
* Most methods implement a "fluent interface" for easy method call chaining.
*
* @see http://pollinimini.net/blog/php-command-runner/
* @author Iván -DrSlump- Montes <drslump@pollinimini.net>
* @license BSD
<?php
// Escapes a string (if needed) using the concat function for its use
// in xpath expressions.
// Example:
// $xpath = '/*[@value=' . escape_string_xpath("this is "foo's\"!") . ']';
// Becomes:
// /*[@value=concat('this is "foo', "'", 's"!')]
function escape_string_xpath($value) {
@drslump
drslump / validator.js
Created February 14, 2011 20:09
a prof of concept for "Transfer Objects" or "Parameter Objects"
function field() {
var type = 'string',
optional = false,
regexp = null,
custom = null;
return {
'string': function(){ type = 'string'; return this },
'int': function(){ type = 'number'; return this },
'optional': function(){ optional = true; return this },
@drslump
drslump / ResourceInjection.php
Created July 1, 2011 13:13
Simple example of how could look like injecting resources in objects
<?php
// Injects ZF Bootstrap resources in an object based on annotations
function InjectResources($obj) {
$obj = $this;
$reflObj = new \ReflectionObject($obj);
foreach ($reflObj->getProperties() as $prop) {
$doc = $prop->getDocComment();
if (preg_match('/@resource(\s+(?<name>[A-Za-z_]+))?/', $doc, $m)) {
$name = empty($m['name'])
@drslump
drslump / Bootstrap.php
Created July 5, 2011 11:33 — forked from pepe84/App.php
PHP Zend: Resources lazy loading
<?php
class My_Zend_Application_Bootstrap_LazyBootstrap extends Zend_Application_Bootstrap_Bootstrap
{
/**
* Bootstrap implementation
*
* This method may be overridden to provide custom bootstrapping logic.
* It is the sole method called by {@link bootstrap()}.
*
@drslump
drslump / DrupalClass.php
Created August 7, 2011 18:55
Drupal Class to global functions
<?php
class DrupalClass {
static $instances = array();
public function __construct()
{
$class = get_class($this);
if (isset(self::$instances[$class])) return;