Skip to content

Instantly share code, notes, and snippets.

@hakre
hakre / reflection-named-parameter.php
Created December 28, 2011 06:17
Callback Decorator ReflectedCallback
<?php
/**
* Callback Decorator
*
* Providing reflection and invoking
* with named function arguments.
*
* @version 0.0.1
* @see http://stackoverflow.com/q/8649536/367456
<data>
<hello>paste your xml here</hello>
</data>
@hakre
hakre / dl-file.php
Created January 2, 2012 21:41
Wordpress login to download uploaded files
<?php
/*
* dl-file.php
*
* Protect uploaded files with login.
*
* @link http://wordpress.stackexchange.com/questions/37144/protect-wordpress-uploads-if-user-is-not-logged-in
*
* @author hakre <http://hakre.wordpress.com/>
* @license GPL-3.0+
@hakre
hakre / xpath_match_all
Created February 21, 2012 22:28 — forked from gooh/xpath_match_all
function for people whining that preg_match_all is less to type and concluding from it that regex must be better for parsing html than a dom parser
<?php
/**
* @param string $query xpath query/expression
* @param string $html (optional)
* @return array|FALSE array on success, FALSE on error
*/
function xpath_match_all($query, $html = '')
{
static $dom;
static $xpath;
@hakre
hakre / TextRange.php
Created February 23, 2012 18:56
TextRange and TextRangeTrimmer HTML/DOMDocument text processing classes
<?php
/**
* TextRange.php - DOMDocument based Textrange and text manipulation
*
* @author hakre <http://hakre.wordpress.com/credits>
* @version 1.1.1
*/
/**
* TextRange - Collection of DOMText nodes
@hakre
hakre / flip-orientation.php
Created February 25, 2012 19:41
flip orientation
<?php
/**
* @link http://stackoverflow.com/q/9445369/367456
*/
$array = range('A', 'M');
$columns = 4;
$length = count($array);
print_matrix($array, $columns);
@hakre
hakre / some-iterator-fun.php
Created February 28, 2012 06:59
Some Iterator Fun
<?php
/*
* Some Iterator Fun
*
* @link http://hakre.wordpress.com/2012/02/28/some-php-iterator-fun/
*/
/**
* Iterator that fetches each iteration value from a
@hakre
hakre / nested-tree-and-iterator.php
Created February 28, 2012 17:35
Getting nested set model into a <ul> but hiding “closed” subtrees
<?php
/**
* Getting nested set model into a <ul> but hiding “closed” subtrees
*
* @link http://stackoverflow.com/a/7786733/367456
*/
// $categories = get_categories();
$categories = get_categories_large();
$current = array('lft' => '14', 'rgt' => '13');
@hakre
hakre / xmlrpc-discovery.php
Created February 28, 2012 21:46
XMLRPC Discovery Service
<?php
/**
* XMLRPC Discovery and XMLRPC Introspection Service
*
* <http://xmlrpc-c.sourceforge.net/introspection.html>
*
* Uses the PHP XML-RPC extension <http://php.net/manual/en/book.xmlrpc.php>
*
* Has an adapter interface to other libraries as well, a working example implementation
* exists for XML-RPC for PHP <http://phpxmlrpc.sourceforge.net/doc-2/>
@hakre
hakre / magnet-links-bittorrent.php
Created March 1, 2012 13:13
Magnet links library for PHP