Skip to content

Instantly share code, notes, and snippets.

View jasonhofer's full-sized avatar

Jason Hofer jasonhofer

  • Sarnia, Ontario
View GitHub Profile
@jasonhofer
jasonhofer / ant-which.xml
Last active October 1, 2015 08:07
Apache Ant "which" scriptdef
<property environment="env" />
<property name="env.PATH" value="${env.Path}" /><!-- because windows -->
<scriptdef name="which" language="javascript">
<attribute name="command" />
<attribute name="property" />
<![CDATA[
var cmd = attributes.get("command") || "";
var prop = attributes.get("property") || "";
@jasonhofer
jasonhofer / ant-property-shortcuts.xml
Last active October 1, 2015 08:08
Apache Ant property shortcuts
<property name="\n" value="${line.separator}" />
<property name="/" value="${file.separator}" />
<property name=":" value="${path.separator}" />
<!-- tab char -->
<script language="javascript">project.setUserProperty("\\t", "\t");</script>
<!-- for surrounding command line options -->
<condition property="'" value="&quot;" else="'">
<os family="windows" />
@jasonhofer
jasonhofer / ant-php-macrodef.xml
Created March 1, 2012 18:07
Apache Ant "php" macrodef for executing PHP code
<!--
@todo new attributes "include" and/or "require" which take csv file lists. useful for presetdefs
@todo new attribute "namespace" (useful?)
@todo use "return" instead of "echo", or allow both. maybe use attributes "returnProperty" and "outputProperty" instead of just "property"
@todo could (optionally) predefine some variables, such as $basedir
@todo could (optionally) use "echoProperties" to dump properties to a temp file and load them into a predefined $ant, $properties, or $p array
-->
<macrodef name="php" description="Executes PHP code">
<attribute name="code" default="" />
@jasonhofer
jasonhofer / ant-props-setup.xml
Created March 2, 2012 14:42
Apache "Props" Ant Library setup
<!--
Requires Ant 1.8+
Home page: http://ant.apache.org/antlibs/props
SVN URL: https://svn.apache.org/repos/asf/ant/antlibs/props/trunk
ViewVC: http://svn.apache.org/viewvc/ant/antlibs/props/trunk
-->
<taskdef resource="org/apache/ant/props/antlib.xml"
classpath="${lib.dir}/ant-props-1.0Alpha.jar" />
@jasonhofer
jasonhofer / ant-color-output.xml
Created March 2, 2012 14:45
Apache Ant color output
ant -logger org.apache.tools.ant.listener.AnsiColorLogger
@jasonhofer
jasonhofer / directory-tree-array.php
Last active July 15, 2022 10:26
Directory tree array
<?php
/**
* Creates a tree-structured array of directories and files from a given root folder.
*
* Gleaned from: http://stackoverflow.com/questions/952263/deep-recursive-array-of-directory-structure-in-php
*
* @param string $dir
* @param string $regex
* @param boolean $ignoreEmpty Do not add empty directories to the tree
* @return array
@jasonhofer
jasonhofer / simple-output-colorizer.php
Last active October 3, 2015 02:07
Simple output colorizer
<?php
/**
* Very simple output colorizer. Only changes the foreground color.
* Tokens take the form {colorname}.
*
* Bright colors start with 'b', as in 'bgreen' and 'bblue'.
*
* You can escape brackets using double brackets {{ and }}
*
* PHP >= 5.3.0 (but could easily be modified to work with earlier versions)
@jasonhofer
jasonhofer / ant-js-snippets.js
Created May 7, 2012 15:29
Apache Ant Javascript snippets
//
// Ant Javascript snippets
//
import(java.io.File);
importClass(Packages.org.apache.tools.ant.types.Environment);
importClass(Packages.org.apache.tools.ant.taskdefs.Echo);
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g, "");
@jasonhofer
jasonhofer / doctrine-dql-type-function.php
Last active December 30, 2021 21:11
Doctrine TYPE() function for DQL. Provides a way to access an entity's discriminator field in DQL queries.
<?php
namespace My\Doctrine\ORM\Query\Functions;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\QueryException;
use Doctrine\ORM\Query\SqlWalker;
@jasonhofer
jasonhofer / doctrine-create-discriminator-map-listener.php
Last active October 7, 2016 14:04
A Doctrine listener that allows you to inject your own generated discriminator map rather than have to define it in an entity's class doc block with the @DiscriminatorMap() annotation.
<?php
/**
* The DiscriminatorMap() annotation in an entity's class doc comment can be
* empty, but if it is, Doctrine will create a default discriminator map
* using the lower-case short name of each sub-class as the discriminator
* "type" name. This may be just fine for your purposes, but if not,
* this listener provides a way to programmatically inject your own
* discriminator map.
*
* To prevent Doctrine from creating the default discriminator map, you will