Skip to content

Instantly share code, notes, and snippets.

View aaronpk's full-sized avatar

Aaron Parecki aaronpk

View GitHub Profile
@aaronpk
aaronpk / media-endpoint.php
Last active March 6, 2021 23:47
an example of a Micropub Media Endpoint https://www.w3.org/TR/micropub/#media-endpoint
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Authorization');
if(isset($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'text/plain') !== false) {
$format = 'text';
} else {
header('Content-Type: application/json');
$format = 'json';
}
{
"type": [
"h-entry"
],
"properties": {
"published": [
"2017-01-01 12:00:00"
],
"checkin": [{
"type": [
<?php
class Stardate {
# Ported from https://github.com/pioz/stardate/blob/master/lib/stardate.rb
private static $year_0 = 2323;
private static $year_duration = 365.2425;
public static function date_to_stardate($date) {
# days since the beginning of the year
@aaronpk
aaronpk / email-auth.rb
Created March 6, 2017 21:44
Prototype of two-factor authentication using email and a password
require 'jwe'
# Set your password and email address
key = Digest::SHA256.digest('p455w0rd!')
payload = 'aaron@parecki.com'
# Create the JWE string
encrypted = JWE.encrypt(payload, key, alg:'dir')
# Put the resulting string on your website:
body {
color: #212121;
font-family: "Helvetica Neue", "Calibri Light", Roboto, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
letter-spacing: 0.02em;
}
@aaronpk
aaronpk / canonical.php
Created December 20, 2016 01:47
Given an input URL, find the canonical URL after following redirects and looking at rel=canonical
<?php
if(!isset($_GET['url'])) {
?>
<form action="" method="get">
<input type="url" name="url">
<input type="submit" value="Go">
</form>
<?
die();
}
function addParagraphIDs() {
$("section").each(function(){
var section_id = $(this).attr("id");
var counter = 1;
$(this).find("p").each(function(){
var paragraph_id = section_id + "-p-" + counter;
counter++;
$(this).attr("id", paragraph_id);
});
var counter = 1;
@aaronpk
aaronpk / issue-commenters.php
Last active September 18, 2016 15:24
Example of extracting commenter names from the offline issues HTML from https://github.com/jreinhardt/handkerchief/pull/33
// https://github.com/indieweb/php-mf2/blob/master/Mf2/Parser.php
require_once 'Mf2/Parser.php';
$parsed = Mf2\parse(file_get_contents('issues-webmention.html'));
$authors = [];
foreach($parsed['items'][0]['children'] as $comment) {
$author = strtolower($comment['properties']['author'][0]);
if(!in_array($author, $authors))
<!DOCTYPE html>
<!-- aaronpk/micropub.rocks -->
<html>
<head>
<meta charset="utf-8"/>
<!-- jquery-2.1.1.min.js -->
<script type="text/javascript">
/*! jQuery v2.1.1 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */