Skip to content

Instantly share code, notes, and snippets.

hakre hakre

View GitHub Profile
@hakre
hakre / test-query-arg.php
Created Mar 23, 2011
behavior test add_query_arg_old
View test-query-arg.php
<?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
View commandline.php
<?php
/**
* CommandLine class
*
* @package Framework
*/
/**
* Command Line Interface (CLI) utility class.
*
* @author Patrick Fisher <patrick@pwfisher.com>
@hakre
hakre / commandline.php
Created Apr 10, 2011
Just for fun, here is a compacted version:
View commandline.php
<?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
Extend Wordpress Admin Bar with any kind of content you like - not just links.
View my-html-admin-bar.php
<?php
$getHtml = function($id) {
?>
<div><a>
Some custom HTML
</a></div>
<?php
};
@hakre
hakre / gist:1018156
Created Jun 10, 2011
search array in array note
View gist:1018156
<?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 Jul 21, 2011
XMLReader based parser in form of an iterator and filteriterator
View xml-books.php
<?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 Sep 26, 2015
Former Print_r Converter Gist, now gone full-blown: https://github.com/hakre/print_r-converter
View README.md

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.

View example.php
<?php
$response = <<<RESP
<Groups>
<Group>
<Item>
<Description>One Item - Color: Black, Size: 9</Description>
</Item>
</Group>
<Group>
View xmltree_dump_includes.php
<?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 Dec 26, 2011
Example of a request and response object with cUrl
View myrequest.php
<?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
You can’t perform that action at this time.