Skip to content

Instantly share code, notes, and snippets.

View Zegnat's full-sized avatar

Martijn van der Ven Zegnat

View GitHub Profile
@Zegnat
Zegnat / setup.md
Last active June 5, 2018 13:52
Setting up an offline Micropub testing environment, combining 3 separate PHP projects!

Testing Micropub, completely offline, with nanopub, Selfauth, and Mintoken.

this setup should be done in a directory that is being served at http://offlinepub.test/. When done, it should be possible to point a Micropub client at that URL and post.

IMPORTANT: This does not lead to a production safe setup. The tokens DB is put in a public directory, the APP_KEY for Selfauth is made known through this post, etc. But for offline testing, all should be good.

@Zegnat
Zegnat / example.php
Created April 24, 2018 17:30
Example of using a PSR-7 library to parse an incoming request that contains one or more `photo` uploads.
<?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();
<!-- 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>
@Zegnat
Zegnat / README.md
Last active December 25, 2021 22:37
JSON Schema for Microformats

The schema has been moved to its own repository so unit tests could be added. This makes sure the schema actually works for known microformats2 parser outputs.

Find the repository at: Zegnat/microformats2-json-schema and the latest version of the schema JSON on at ./schema.json.

<?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 December 14, 2017 16:02
wget (like my browser) fails to get the file, but cURL does just fine.
$ 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
<?php
declare(strict_types=1);
namespace Zegnat\Utilities;
use League\Uri\Schemes\Http;
use League\Uri\Modifiers\Resolve;
use League\Uri\UriException;
class LinkExtractor
@Zegnat
Zegnat / README.md
Last active January 30, 2019 16:25
Generate Magic login URL for Micropub endpoints

Generate Magic login URL for Micropub endpoints

To make Micropub requests, the specification requires a Bearer token. Many current Micropub clients force the user to go through IndieAuth to obtain this, which means you need to have the required authorization and token endpoints set-up before getting started with Micropub.

The file token-provider.php implements the happy path for the IndieAuth dance resulting in providing the Micropub client with whatever token the user has provided.

Why

raziellight on IRC was trying to get the Micropub client Omnibear to work, and that required him to figure out how to set-up IndieAuth from scratch. I think this is way too big of an investment for getting started with Micropub. It was time to cut out the middle man (or protocol, in this case

<?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'));
<style>
table {
border-collapse: collapse;
}
th, td {
padding: .5em 2em .5em .5em;
border-right: 1px dotted #AAA;
border-bottom: 1px solid #CCC;
}
th {