Skip to content

Instantly share code, notes, and snippets.


Martijn van der Ven Zegnat

View GitHub Profile
Zegnat / example.php
Created Apr 24, 2018
Example of using a PSR-7 library to parse an incoming request that contains one or more `photo` uploads.
View example.php
use \Nyholm\Psr7\Factory\ServerRequestFactory;
// Use the (draft) PSR-17 Factory to create our PSR-7 Request object:
$incomingRequest = ServerRequestFactory::createServerRequestFromGlobals();
// Check for uploaded files on the Request object.
// @see
$files = $incomingRequest->getUploadedFiles();
View article-example.html
<!-- HTML5 example article, with mf2 instead of, -->
<article class="h-entry">
<h1 class="p-name">The Very First Rule of Life</h1>
<p><time class="dt-published" datetime="2009-10-09">3 days ago</time></p>
<data class="u-url" value="?comments=0"></data><!-- <link> isn’t valid here, use <data>. -->
<p>If there's a microphone anywhere near you, assume it's hot and
sending whatever you're saying to the world. Seriously.</p>
View KnownValetDriver.php
class KnownValetDriver extends BasicValetDriver
public function serves($sitePath, $siteName, $uri)
return is_file($sitePath . '/version.known');
public function isStaticFile($sitePath, $siteName, $uri)
Zegnat / gist:f5c3806c6be0ea5244359833acbf96a3
Created Dec 14, 2017
wget (like my browser) fails to get the file, but cURL does just fine.
View gist:f5c3806c6be0ea5244359833acbf96a3
$ wget
--2017-12-14 17:00:18--
Resolving, 2a04:4e42:14::403
Connecting to||:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-12-14 17:00:18 ERROR 404: Not Found.
$ curl -O
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
View LinkExtractor.php
namespace Zegnat\Utilities;
use League\Uri\Schemes\Http;
use League\Uri\Modifiers\Resolve;
use League\Uri\UriException;
class LinkExtractor
View bday.php
// Create a DateTimeImmutable with the date and time to compare to.
// Use your current timezone, or the timezone of your visitor. I am in Sweden.
$now = new DateTimeImmutable('now', new DateTimeZone('Europe/Stockholm'));
// Create the object with your birthday.
$birthday = $now->setTimezone(new DateTimeZone('Europe/Amsterdam')); // Born in the Netherlands
$birthday = $birthday->setDate(1991, 10, 23); // On the 23rd of October, 1991
$birthday = $birthday->setTime(20, 9); // 9 minutes past 8 in the evening
// What year is it?
$currentyear = intval($now->format('Y'));
View pickAnyEncoding.php
table {
border-collapse: collapse;
th, td {
padding: .5em 2em .5em .5em;
border-right: 1px dotted #AAA;
border-bottom: 1px solid #CCC;
th {
Zegnat / custom.css
Last active May 14, 2017
Facebook with PII censored.
View custom.css
/* People’s names. */
span > a[data-hovercard^="/ajax/hovercard/user.php?"], /* poster and shares */
.UFICommentActorName, /* comments */
.UFICommentBody .profileLink /* inside comments */
background-color: currentColor;
/* People’s avatars. */
a[data-hovercard^="/ajax/hovercard/user.php?"] > div > img._s0, /* poster */
Zegnat / Zegnat.Utils.ServerRequestFromGlobals.php
Last active Apr 10, 2017
Construct a PSR-7 ServerRequest through a PSR-17 factory for the current HTTP request.
View Zegnat.Utils.ServerRequestFromGlobals.php
namespace Zegnat\Utils;
use Interop\Http\Factory\ServerRequestFactoryInterface;
use Interop\Http\Factory\StreamFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
Zegnat / .htaccess
Last active Apr 5, 2017
This emulates in a 2 line .htaccess file. Compatible with any Apache server with mod_alias enabled.
View .htaccess
RedirectMatch 303 /(.+)$!$1
Redirect 303 /
You can’t perform that action at this time.