Skip to content

Instantly share code, notes, and snippets.

Avatar

Aaron Parecki aaronpk

View GitHub Profile
@aaronpk
aaronpk / github-oauth2-client.php
Created Sep 3, 2012
Simple PHP example of using Github's OAuth 2 API
View github-oauth2-client.php
<?php
define('OAUTH2_CLIENT_ID', '');
define('OAUTH2_CLIENT_SECRET', '');
$authorizeURL = 'https://github.com/login/oauth/authorize';
$tokenURL = 'https://github.com/login/oauth/access_token';
$apiURLBase = 'https://api.github.com/';
session_start();
@aaronpk
aaronpk / gist:5846789
Last active Apr 18, 2021
Added WebFinger support to my email address using one rewrite rule and one static file.
View gist:5846789
[aaron@parecki.com www]$ cat .htaccess
RewriteEngine on
RewriteCond %{QUERY_STRING} resource=acct:(.+)
RewriteRule ^\.well-known/webfinger /profile/%1? [L]
[aaron@parecki.com www]$ cat profile/aaron@parecki.com
{
"subject": "acct:aaron@parecki.com",
"links": [
{
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 README.md

Swap out the two URLs (first is source, second is target) then run with curl:

curl -X POST -d @pingback.xml http://example.com/xmlrpc
@aaronpk
aaronpk / _howto.md
Last active Nov 14, 2020
How to compile and install spatialite on iOS
View _howto.md

Spatialite for iOS

Install compiler dependencies

brew install automake autoconf libtool libxml2 pkg-config
brew link libxml2

Build libspatialite

View aqi.php
<?php
function aqiFromPM($pm) {
if($pm >= 350.5)
return scale($pm, 500, 401, 500, 350.5);
if($pm >= 250.5)
return scale($pm, 400, 301, 350.4, 250.5);
if($pm >= 150.5)
return scale($pm, 300, 201, 250.4, 150.5);
if($pm >= 55.5)
@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();
}
@aaronpk
aaronpk / webmention.html
Last active Mar 17, 2019
Display webmention count with no jQuery or external Javascript libraries
View webmention.html
<span id="webmention-count"></span>
<script type="text/javascript">
function loadWebmentions(data){
document.getElementById("webmention-count").innerHTML = data.count + " mentions";
}
</script>
<script type="text/javascript" src="http://webmention.io/api/count?jsonp=loadWebmentions&amp;target=http://example.com/page/100"></script>
View install-composer.sh
#!/bin/sh
EXPECTED_SIGNATURE="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_SIGNATURE="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
if [ "$EXPECTED_SIGNATURE" != "$ACTUAL_SIGNATURE" ]
then
>&2 echo 'ERROR: Invalid installer signature'
rm composer-setup.php