Skip to content

Instantly share code, notes, and snippets.

View nonsensecreativity's full-sized avatar

Hermanto Lim nonsensecreativity

View GitHub Profile
<?php
/*
* Some Iterator Fun
*
* @link http://hakre.wordpress.com/2012/02/28/some-php-iterator-fun/
*/
/**
* Iterator that fetches each iteration value from a
@nonsensecreativity
nonsensecreativity / nested-tree-and-iterator.php
Created July 28, 2017 10:09 — forked from hakre/nested-tree-and-iterator.php
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');
<?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.
*
@nonsensecreativity
nonsensecreativity / datetime-ranges.php
Created July 28, 2017 10:04 — forked from hakre/datetime-ranges.php
DateTime Range and Ranges
<?php
/**
* @link http://stackoverflow.com/questions/13129336/split-a-time-range-into-pieces-by-other-time-ranges
* @link https://gist.github.com/gists/3977645
* @author hakre
*/
class Range
{
<?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
*/
@nonsensecreativity
nonsensecreativity / Micro.php
Created July 28, 2017 10:00 — forked from hakre/Micro.php
schema.org microdata reading PHP class for use with DOMDocument or SimpleXML.
<?php
/*
* Micro Class For Micro Data
* Powered by libxml
*
* @author hakre <http://hakre.wordpress.com/>
* @version 0.7.1
*/
/**
@nonsensecreativity
nonsensecreativity / csv-to-xml.php
Created July 28, 2017 09:58 — forked from hakre/csv-to-xml.php
Converting a massive CSV to a specific XML format
<?php
/*
* Converting a massive CSV to a specific XML format
*
* @link http://stackoverflow.com/a/32034227/367456
*/
/**
* Class XmlEncoder
*
@nonsensecreativity
nonsensecreativity / StreamNotifyPrinter.php
Created July 28, 2017 09:58 — forked from hakre/StreamNotifyPrinter.php
StreamNotifyPrinter - Print out PHP Stream Notifications to target channel (default: STDERR).
<?php
/**
* StreamNotifyPrinter
*
* @author hakre <http://hakre.wordpress.com>
* @version 0.0.2
* @example http://stackoverflow.com/a/24711469/367456
* @link https://gist.github.com/hakre/8ba2c0d49b7baf062acd
*/
@nonsensecreativity
nonsensecreativity / GroupIterator.php
Created July 16, 2017 07:21 — forked from jm42/GroupIterator.php
PHP `itertools.groupby` implementation
<?php
class GroupIterator implements Iterator
{
protected $keyfunc;
protected $iter;
protected $key = null;
protected $value = null;
<?php
header('Content-Type: text/html; charset=utf-8');
#https://wiki.php.net/rfc/generators
require '../vendor/autoload.php';
/*
Os Generators fornecem uma maneira fácil, livre de clichês para
implementar iterators.