Skip to content

Instantly share code, notes, and snippets.

Martijn van der Ven Zegnat

Block or report user

Report or block Zegnat

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Zegnat
Zegnat / microformat.schema.json
Last active Aug 2, 2019
JSON Schema for Microformats
View microformat.schema.json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"type": { "$ref": "#/definitions/types" },
"properties": { "$ref": "#/definitions/properties" },
"children": {
"type": "array",
"items": { "$ref": "#" }
},
@Zegnat
Zegnat / README.md
Last active Mar 14, 2019
Simple script for accessing the contents of an encrypted andOTP backup.
View README.md

andOTP Decrypt

Simple script for accessing the contents of an encrypted andOTP backup. As long as Sodium is available this does not require any dependencies outside of PHP.

This was written as a replacement for [asmw/andOTP-decrypt][], which I found a little annoying to get going and depends on several external packages. (Hold! Was PHP easier than Python here? Oh my!)

Usage

To decrypt and write to a JSON file:

@Zegnat
Zegnat / README.md
Last active Jan 30, 2019
Generate Magic login URL for Micropub endpoints
View README.md

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

@Zegnat
Zegnat / Innertext.php
Last active Oct 19, 2018
🏃🐉 Run. Here be dragons.
View Innertext.php
<?php
declare(strict_types=1);
namespace Zegnat\Innertext;
class Innertext
{
const LF = "\n";
const CRLF = "\r\n";
@Zegnat
Zegnat / README.md
Created Feb 24, 2012
Fixing your skip links. [JS]
View README.md

Fixing your skip links.

Read Damon Muma on this. He proposes the following jQuery solution (inspired by Thompson, fixed by me):

// Apply focus properly when accessing internal links with keyboard in WebKit browsers.
$("a[href^='#']").not("a[href='#']").click(function() {
   $("#"+$(this).attr("href").slice(1)+"").focus();
});
@Zegnat
Zegnat / authdiag.php
Last active Aug 7, 2018
Upload to a web server on an accessible path. Navigate to it in the browser. Copy the URL from the address bar and paste it in the form. Run the test to see if your server gets Authorization headers!
View authdiag.php
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$auth = filter_input(
INPUT_POST,
'auth',
FILTER_VALIDATE_REGEXP,
array('options' => array('regexp' => '@^authtest_\d+$@'))
@Zegnat
Zegnat / setup.md
Last active Jun 5, 2018
Setting up an offline Micropub testing environment, combining 3 separate PHP projects!
View setup.md

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 / martijnsclock.1s.php
Created May 15, 2018
BitBar (https://getbitbar.com/) plugin for a variable drop-down of time zones. Also does unix epoch time, and copying of ISO timestamps to the clipboard.
View martijnsclock.1s.php
#!/usr/local/bin/php
<?php
$now = new \DateTimeImmutable(null, new \DateTimeZone('UTC'));
$copy = getopt('c:');
if (count($copy) > 0) {
// Make sure to use the local /bin/echo executable, exec() runs sh and native echo
// may not do what you expect. https://stackoverflow.com/a/40225695
exec('/bin/echo -n ' . escapeshellarg($copy['c']) . ' | pbcopy', $devnull, $status);
@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>
You can’t perform that action at this time.