Skip to content

Instantly share code, notes, and snippets.

Avatar

Aaron Parecki aaronpk

View GitHub Profile
View media-endpoint.php
<?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';
}
View gist:e197ce9a82cb54e5d5a072c751d73550
{
"type": [
"h-entry"
],
"properties": {
"published": [
"2017-01-01 12:00:00"
],
"checkin": [{
"type": [
View stardate.php
<?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 Mar 6, 2017
Prototype of two-factor authentication using email and a password
View email-auth.rb
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:
View good-enough.css
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 Dec 20, 2016
Given an input URL, find the canonical URL after following redirects and looking at rel=canonical
View canonical.php
<?php
if(!isset($_GET['url'])) {
?>
<form action="" method="get">
<input type="url" name="url">
<input type="submit" value="Go">
</form>
<?
die();
}
View add-paragraph-ids.js
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 Sep 18, 2016
Example of extracting commenter names from the offline issues HTML from https://github.com/jreinhardt/handkerchief/pull/33
View issue-commenters.php
// 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))
View index.html
<!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 */