Skip to content

Instantly share code, notes, and snippets.

Barnaby Walters barnabywalters

Block or report user

Report or block barnabywalters

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
View nominatim.php
// where $app is a silex/pimple container — this could easily be rewritten as an ordinary function though
// example usage: list($location, $err) = $app['nominatim.reverse']([-1.125, 3.526])
function nameForLocation(array $location, $fallback='Unknown Location') {
if (isset($location['name'])) return $location['name'];
if (isset($location['street-address']) and isset($location['region']))
return "{$location['street-address']}, {$location['region']}";
barnabywalters / FifoQueue.php
Last active Dec 30, 2015
Taproot post-storage code as of 2013-12-08. Working live on, probably a little too rusty/specific for convenient use elsewhere but maybe of interest. storage.php is basic functional library — currently it depends on symfony/yaml for post serialisation but that can be replaced with any function capable of serializing an array stru…
View FifoQueue.php
namespace Taproot;
use SplQueue;
class FifoQueue extends SplQueue {
protected $capacity;
public function __construct($capacity) { $this->capacity = $capacity; }
View autolinkHashtags.php
* Given a string and a baseurl, finds all hashtags matching
* `#[\-_a-zA-Z0-9]+` and wraps them in an `a` element with `rel=tag` set
* and a `href` of baseurl + '/' + tagname without the #.
function autolinkHashtags($text, $baseUrl) {
$baseUrl = rtrim($baseUrl, '/');
barnabywalters / template.php
Created Nov 21, 2013
Dumbest PHP template rendering function ever
View template.php
function renderTemplate($template, array $__templateData = array()) {
$render = function ($__path, $render=null) use ($__templateData) {
include __DIR__ . '/../templates/' . $__path . '.php';
return ob_get_clean();
barnabywalters / barnabywalters.json
Created Nov 7, 2013
HTML from, parsed using indieweb/php-mf2-shim as of 2012-11-07
View barnabywalters.json
"rels": {
"shortcut": [
"icon": [
"canonical": [
barnabywalters / opd.js
Last active Dec 21, 2015
Original Post Discovery minimal client side implementation. Requires promisejs (HTTP) and bean (events)
View opd.js
// Original post discovery (in progress)
var noteForms = document.querySelectorAll('.note-post-form');
if (noteForms.length > 0) {
for (var i = 0;i < noteForms.length;i++) {
var form = noteForms[i];
var inReplyToField = form.querySelector('.in-reply-to');
bean.on(inReplyToField, 'blur', function(event) {
var url =;
// TODO: Start loading indicator
promise.get('/services/original-post', {'url': url}).then(function (error, text, xhr) {
barnabywalters / notes.web
Last active Dec 20, 2015
Rough ideas for a gherkin-like environment for writing web applications. Things in parentheses are comments. `do some name` triggers the 'some name' signal defined by `on some name`
View notes.web
on GET /notes
fetch the 20 most recent notes filtered by tag
show as h-feed
on GET /notes/new
the user must be an admin
show autofilled note-form
on GET /notes/{id}
fetch note
barnabywalters / input.html
Last active Dec 17, 2015
Test case for microformats-2 e-* p-* HTML injection potential security hole
View input.html
<span class="h-thing">
<span class="e-content">&lt; Things &gt; &amp;</span>
<span class="h-thing">
<span class="p-content">&lt; Things &gt; &amp;</span>
View gist:5480962
"alternates": [
"url": "",
"rel": "home",
"media": "screen",
"hreflang": "en"
View UriMatcher.php
namespace BarnabyWalters\Rest;
use Symfony\Component\Routing\Matcher\UrlMatcher as Matcher;
* UrlMatcher
* A subclass of Symfony’s UrlMatcher which strips the extension from incoming
You can’t perform that action at this time.