Skip to content

Instantly share code, notes, and snippets.

View jasonhofer's full-sized avatar

Jason Hofer jasonhofer

  • Sarnia, Ontario
View GitHub Profile
<!doctype html>
{% block html_tag %}<html lang="{% block lang 'en' %}">{% endblock %}
<head>
<meta charset="{% block charset 'utf-8' %}">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>{% block title '' %}</title>
<meta name="description" content="{% block description '' %}">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% block head %}{% endblock %}
<head>
<style id="antiClickjack">body {
display: none !important;
}</style>
<script type="text/javascript">
if(self === top) {
var antiClickjack = document.getElementById("antiClickjack");
antiClickjack.parentNode.removeChild(antiClickjack);
} else {
top.location = self.location;
// Originally from https://github.com/ebryn/rsvp-ajax
RSVP.ajax = {
_ajax: function (url, type, params, data) {
var promise = new RSVP.Promise(),
xhr = new XMLHttpRequest();
if (params) { url = url + '?' + $.param(params); }
xhr.onreadystatechange = function (event) {
/*
!(function () {
// Allow: <!--{ fullName }-->
// Instead of: <!-- ko text: fullName --><!-- /ko -->
// See: https://knockoutjs.com/documentation/binding-preprocessing.html
ko.bindingProvider.instance.preprocessNode = function (node) {
if (node.nodeType !== Node.COMMENT_NODE) {
return;
}
const match = node.nodeValue.match(/^[{](.*)[}]$/);
const init = new function () {
let funcs = [],
booted = 0,
doc = document,
ready = fn => {
'loading' === doc.readyState ?
doc.addEventListener('DOMContentLoaded', fn) :
fn();
};
@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
@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 / 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 / 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 / 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