Skip to content

Instantly share code, notes, and snippets.

Avatar

Martijn van der Ven Zegnat

View GitHub Profile
@Zegnat
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
<?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 https://www.php-fig.org/psr/psr-7/#16-uploaded-files
$files = $incomingRequest->getUploadedFiles();
View article-example.html
<!-- HTML5 example article, with mf2 instead of schema.org, https://html.spec.whatwg.org/#article-example -->
<article class="h-entry">
<header>
<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>. -->
</header>
<p>If there's a microphone anywhere near you, assume it's hot and
sending whatever you're saying to the world. Seriously.</p>
<p>...</p>
View KnownValetDriver.php
<?php
class KnownValetDriver extends BasicValetDriver
{
public function serves($sitePath, $siteName, $uri)
{
return is_file($sitePath . '/version.known');
}
public function isStaticFile($sitePath, $siteName, $uri)
@Zegnat
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 https://zegnat.github.io/JS-Relations/index.html
--2017-12-14 17:00:18-- https://zegnat.github.io/JS-Relations/index.html
Resolving zegnat.github.io... 151.101.85.147, 2a04:4e42:14::403
Connecting to zegnat.github.io|151.101.85.147|:443... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-12-14 17:00:18 ERROR 404: Not Found.
$ curl -O https://zegnat.github.io/JS-Relations/index.html
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
View LinkExtractor.php
<?php
declare(strict_types=1);
namespace Zegnat\Utilities;
use League\Uri\Schemes\Http;
use League\Uri\Modifiers\Resolve;
use League\Uri\UriException;
class LinkExtractor
View bday.php
<?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
<style>
table {
border-collapse: collapse;
}
th, td {
padding: .5em 2em .5em .5em;
border-right: 1px dotted #AAA;
border-bottom: 1px solid #CCC;
}
th {
@Zegnat
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 / 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
<?php
declare(strict_types=1);
namespace Zegnat\Utils;
use Interop\Http\Factory\ServerRequestFactoryInterface;
use Interop\Http\Factory\StreamFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
@Zegnat
Zegnat / .htaccess
Last active Apr 5, 2017
This emulates https://github.com/lazd/mdn.io/ in a 2 line .htaccess file. Compatible with any Apache server with mod_alias enabled.
View .htaccess
RedirectMatch 303 /(.+)$ https://duckduckgo.com/?q=!+site:developer.mozilla.org+$1
Redirect 303 / https://developer.mozilla.org/en-US/docs/JavaScript
You can’t perform that action at this time.