Skip to content

Instantly share code, notes, and snippets.

@hakre
hakre / test-query-arg.php
Created March 23, 2011 07:05
behavior test add_query_arg_old
<?php
/**
* test-query-arg.php
*
* USAGE:
*
* Place into wordpress install folder, then
* request it via the browser.
*
* @see https://core.trac.wordpress.org/ticket/16943
<?php
/**
* CommandLine class
*
* @package Framework
*/
/**
* Command Line Interface (CLI) utility class.
*
* @author Patrick Fisher <patrick@pwfisher.com>
@hakre
hakre / commandline.php
Created April 10, 2011 06:51
Just for fun, here is a compacted version:
<?php
function parseArgs($argv){
array_shift($argv); $o = array();
foreach ($argv as $a){
if (substr($a,0,2) == '--'){ $eq = strpos($a,'=');
if ($eq !== false){ $o[substr($a,2,$eq-2)] = substr($a,$eq+1); }
else { $k = substr($a,2); if (!isset($o[$k])){ $o[$k] = true; } } }
else if (substr($a,0,1) == '-'){
if (substr($a,2,1) == '='){ $o[substr($a,1,1)] = substr($a,3); }
else { foreach (str_split(substr($a,1)) as $k){ if (!isset($o[$k])){ $o[$k] = true; } } } }
@hakre
hakre / my-html-admin-bar.php
Created May 15, 2011 13:51
Extend Wordpress Admin Bar with any kind of content you like - not just links.
<?php
$getHtml = function($id) {
?>
<div><a>
Some custom HTML
</a></div>
<?php
};
@hakre
hakre / gist:1018156
Created June 10, 2011 02:46
search array in array note
<?php
$for = array('ac', 'bc');
$in = array('ax', 'ac', 'bc', 'cc');
echo search($for, $in); // 1
/**
* Search non-keyed array $for in non-keyed array $in
* and returning it's index position, or false if not
* found.
*
@hakre
hakre / xml-books.php
Created July 21, 2011 14:08
XMLReader based parser in form of an iterator and filteriterator
<?php
/*
XMLReader based parser in form of an iterator and filteriterator
Author: hakre <hakre.wordpress.com>
Copyright (c) 2011, some rights reserved
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@hakre
hakre / README.md
Last active September 26, 2015 13:17
Former Print_r Converter Gist, now gone full-blown: https://github.com/hakre/print_r-converter

Print_r Converter

As of September 2013, the repository has been moved from this Github Gist (hakre/1102761) over to a public Github repository in my account. You can find it now here:

Please visit that address for more information, updates and code.

<?php
$response = <<<RESP
<Groups>
<Group>
<Item>
<Description>One Item - Color: Black, Size: 9</Description>
</Item>
</Group>
<Group>
@hakre
hakre / xmltree_dump_includes.php
Created December 25, 2011 22:46
Dump XML as Tree
<?php
/*
* Dump XML (DOMNode) as Tree.
*
* @author hakre <http://hakre.wordpress.com/>
* @link http://stackoverflow.com/q/684227/367456
* @link http://stackoverflow.com/q/12108324/367456
*/
abstract class IteratorDecoratorStub implements OuterIterator
@hakre
hakre / myrequest.php
Created December 26, 2011 13:37
Example of a request and response object with cUrl
<?php
/*
* @link http://codepad.viper-7.com/OtahKC
* @link http://stackoverflow.com/q/8632366/367456
*/
/**
* curl based request class that fullfils my needs
*/
class MyRequest