Skip to content

Instantly share code, notes, and snippets.

Avatar

Martijn van der Ven Zegnat

View GitHub Profile
@Zegnat
Zegnat / GeminiStreamWrapper.php
Created Aug 15, 2021
Add gemini:// support for file_get_contents(). Will turn into proper repo with Composer support later.
View GeminiStreamWrapper.php
<?php declare(strict_types=1);
namespace Zegnat\Gemini;
/**
* @see https://www.php.net/manual/en/class.streamwrapper.php
*/
final class GeminiStreamWrapper {
/** @var resource $context if a stream context was provided it will be set here, even before __construct */
public $context;
@Zegnat
Zegnat / background.js
Created Jan 6, 2021
Swapping between two browser context menus depending on the amount of selected tabs.
View background.js
let single = true
const menus = {
single: browser.menus.create({
contexts: ['tab'],
title: '&Close Tab'
}),
selection: browser.menus.create({
contexts: ['tab'],
title: '&Close Tabs',
@Zegnat
Zegnat / yt.html
Last active Nov 8, 2020
I keep forgetting how I can do sleek YouTube embeds. Here is one from a project. Still tweaking.
View yt.html
<!--
Embedded Youtube player that combines:
* https://jameshfisher.com/2017/08/30/how-do-i-make-a-full-width-iframe/
* https://css-tricks.com/lazy-load-embedded-youtube-videos/
* https://stackoverflow.com/a/42555610/3225372
* https://web.dev/iframe-lazy-loading/
* https://github.com/paulirish/lite-youtube-embed/blob/a927d63781883088c185cb69a0baade52732ab3e/src/lite-yt-embed.js#L28
Other things I am still thinking of adding:
* https://www.maxlaumeister.com/articles/hide-related-videos-in-youtube-embeds/
-->
@Zegnat
Zegnat / cal.php
Created Nov 5, 2020
Quicky to plain text calendar generation
View cal.php
<?php
$tz = new DateTimeZone('UTC');
$now = (new DateTimeImmutable('now', $tz))->setTime(12, 0, 0, 0);
$start = filter_input(INPUT_GET, 'start', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '@\d{4,}-\d\d-\d\d@']]);
$end = filter_input(INPUT_GET, 'end', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '@\d{4,}-\d\d-\d\d@']]);
if (
is_string($start) &&
($startParts = array_map('intval', explode('-', $start))) &&
@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 / 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 / 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 / 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 / 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 / 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();