Skip to content

Instantly share code, notes, and snippets.

@hakre
hakre / gist:826061
Created February 14, 2011 15:48
WP_Query_Columns - Columns for the loop. - http://wordpress.stackexchange.com/q/9308/178
<?php
/**
* get_columns_array
*
* Columns for the loop, single function interface (limited)
*
* Copyright (c) 2011 hakre <http://hakre.wordpress.com/>, some rights reserved
*
* USAGE:
@hakre
hakre / attacks-xml.php
Created April 18, 2012 21:49
PHP DOMDocument/libxml billion laughs / quadratic blowup
<?php
/**
* @link http://stackoverflow.com/q/10212752/367456
* @link http://msdn.microsoft.com/en-us/magazine/ee335713.aspx
*/
$file = 'billion-laughs-2.xml';
$file = 'quadratic-blowup-2.xml';
printf("Mem: %s (Peak: %s)\n", number_format(memory_get_usage(), 0, '', ' '), number_format(memory_get_peak_usage(), 0, '', ' '));
<?php
/*
* Get all 52 weeks of the year and work days given the first day of the January of current year
* @link http://stackoverflow.com/a/14147613/367456
* @author hakre <http://hakre.wordpress.com/credits>
*/
/**
* Filter a DatePeriod by year
*/
@hakre
hakre / CachedPDOStatement.php
Created March 13, 2013 13:35
CachtingIterator for a PDOStatement with support for multiple iterations.
<?php
/**
* Class CachedPDOStatement
*
* CachingIterator for a PDOStatement
*/
class CachedPDOStatement extends CachingIterator
{
private $index;
@hakre
hakre / csv-keyed-spl.php
Created November 27, 2012 09:49
Decorate Iterators - CSV Data Example
<?php
/**
* @link http://stackoverflow.com/q/10181054/367456
*/
/**
* Extending from a TraversableDecorator allows to decorate (change) the Iterator
* being Traversed without changing the object.
*/
@hakre
hakre / other.php
Created June 18, 2017 23:50
inject php declare ticks poc
<?php
/**
* just some file
*/
$a = 1;
if ($a > 0) {
$a += 2;
print($a);
@hakre
hakre / taxonomy-feeds.php
Created February 5, 2011 15:57
WordPress 3.1 Taxonomy Feeds
<?php
/**
* WordPress 3.1 Taxonomy Feeds Plugin (Must-Use)
*
* Copyright (C) 2011 hakre <http://hakre.wordpress.com/>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
@hakre
hakre / schematest.php
Created December 13, 2012 18:57
Speeding up XML schema validations of a batch of XML files against the same XML schema (XSD)
<?php
/**
* @link http://stackoverflow.com/questions/13865149/speeding-up-xml-schema-validations-of-a-batch-of-xml-files-against-the-same-xml
*/
$mapping = [
'http://www.w3.org/2002/08/xhtml/xhtml1-transitional.xsd' => 'schema/xhtml1-transitional.xsd',
'http://www.w3.org/2001/xml.xsd' => 'schema/xml.xsd',
];
@hakre
hakre / DateInterval_11556731.php
Created July 19, 2012 09:12
How we can add two date intervals in PHP
<?php
/**
* How we can add two date intervals in PHP
* @link http://stackoverflow.com/q/11556731/367456
* @link http://codepad.viper-7.com/oBW2le
*
* NOTE: This code is rough.
*/
header("Content-Type: text/plain;");
@hakre
hakre / docker-minimal-example.sh
Created October 23, 2019 20:36
Docker Run without "docker run"
<<'EOD' docker build --rm --tag rewrite-tester --no-cache -
FROM httpd:alpine
RUN set -e \
; sed -i -e 's/^#LoadModule rewrite_module/LoadModule rewrite_module/' \
-e 's/^LogLevel .*$/LogLevel debug rewrite:trace8/' \
-e '\|<Directory "/usr/local/apache2/htdocs">|,\ </Directory> s/^ AllowOverride .*$/ AllowOverride All/' \
/usr/local/apache2/conf/httpd.conf \
; echo -e ' \n\
RewriteEngine On \n\
RewriteBase / \n\