Skip to content

Instantly share code, notes, and snippets.

@hakre
hakre / uri-schemes.xml
Last active December 14, 2015 18:08
Uniform Resource Identifier (URI) Schemes (2013-03-01) --- This is scraped from the Official IANA Registry of URI Schemes HTML; 172 uri-schemes in IANA registry, length from 2 to 23 characters.
<registry xmlns="http://www.iana.org/assignments" id="uri-schemes">
<title>Uniform Resource Identifier (URI) Schemes</title>
<updated>2013-03-01</updated>
<note>This is scraped from the Official IANA Registry of URI Schemes HTML</note>
<scraped href="http://www.iana.org/assignments/uri-schemes.html">2013-03-10</scraped>
<registry id="uri-schemes-1">
<title>Permanent URI Schemes</title>
<xref type="rfc" data="rfc4395"/>
<registration_rule>Expert Review</registration_rule>
<expert>Graham Klyne</expert>
<IfModule mod_rewrite.c>
# skip "real" requests
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [QSA,L]
# all "unreal" requests go to index.php
RewriteRule .* index.php [QSA,L]
</IfModule>
<?php
/**
* PHP Object as property
* @link http://stackoverflow.com/questions/15273033/php-object-as-property
*/
Interface Person
{
/**
* @return string
@hakre
hakre / dom-processing-instructions.php
Last active December 13, 2015 18:58
PHP function in XML?
<?php
/**
* PHP function in XML?
* @link http://stackoverflow.com/q/14888921/367456
* @link https://gist.github.com/hakre/4959346
* @link http://eval.in/9908
* @author hakre <hakre.wordpress.com>
*/
$xml = <<<BUFFER
@hakre
hakre / simplexml-import.php
Created February 12, 2013 11:23
In SimpleXML, how can I add an existing SimpleXMLElement as a child element?
<?php
/**
* In SimpleXML, how can I add an existing SimpleXMLElement as a child element?
*
* @link http://stackoverflow.com/q/767327/367456
* @link http://eval.in/9568
* @link http://3v4l.org/1sI05
*/
/**
@hakre
hakre / gist:4642090
Last active December 11, 2015 18:29
Get nested bracket pairs from a string.
<?php
/**
* PHP: Algorithm for recursive string subset extraction
* @link http://stackoverflow.com/q/14532139/367456
* @link https://gist.github.com/4642090
* @link http://eval.in/7578
*/
$subject = 'abc{def}ghij{kl{mn}o{pq}}r{s{t{u{v}}w}}xyz';
@hakre
hakre / online_image_viewer.php
Last active December 11, 2015 11:28
Codepad Viper Remote Image Viewer - http://codepad.viper-7.com/DqZkYM/55DEV
<?php
/**
* Codepad Viper Remote Image Viewer
*/
$urls = ['http://i.stack.imgur.com/Pa9s3.png'];
$removes = [];
if (isset($_GET['g'])) $urls = array_filter((array) $_GET['g']);
if (isset($_GET['r'])) $removes = (array) $_GET['r'];
@hakre
hakre / RandomIterator.php
Created January 7, 2013 16:44
Random Iterator - Picking n Iterations random out of x Iterations (Reservoir sampling)
<?php
/**
* Random Iterator - Picking n Iterations random out of x Iterations (Reservoir sampling)
*
* TODO Preserve Iteration Keys
*
* @author hakre
*/
class RandomIterator implements IteratorAggregate
{
<?php
/**
* Pagination Class for SQL LIMIT clauses
*
* @author hakre <http://hakre.wordpress.com/>
* @link http://stackoverflow.com/a/23444110/367456
*/
class LimitPagination
{
private $perPage, $page, $totalCount;
<?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
*/