Skip to content

Instantly share code, notes, and snippets.

@barnabywalters
barnabywalters / FifoQueue.php
Last active December 30, 2015 17:49
Taproot post-storage code as of 2013-12-08. Working live on waterpigs.co.uk, 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…
<?php
namespace Taproot;
use SplQueue;
class FifoQueue extends SplQueue {
protected $capacity;
public function __construct($capacity) { $this->capacity = $capacity; }
<?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
barnabywalters / .gitignore
Last active July 12, 2022 16:37
An attempt at making a Composer-compatible repository in a gist
.DS_Store
composer.phar
/vendor/
@barnabywalters
barnabywalters / h-event.html
Created May 4, 2014 14:10
php-mf2 dt-* <data class="value"> parse demonstration
<div class="h-event">
<span class="dt-start">
<data class="value" value="2013-01-01">first day of 2013</data> at
<data class="value" value="21:00">nine in the evening</data>
</div>
@barnabywalters
barnabywalters / authorization.php
Last active August 29, 2015 14:01
indieauth client/server setup code
<?php
// Create a micropub client app — allows users to log in and authorize this app to make requests on their behalf to,
// e.g. a micropub endpoint, authenticates requests based on remember-me cookie.
// $dataToCookie and $dataFromCookie map between the array of information about the current user and the string value
// stored in the remember-me cookie
//
// Adds routes:
// /login
// /authorize
@barnabywalters
barnabywalters / note.yaml
Created June 8, 2014 22:33
Example YAML of one of my notes
id: 4DtGgd
author:
type: h-card
url: 'http://waterpigs.co.uk'
photo: 'http://photos.waterpigs.co.uk/photos/custom/201210/5d5a4d-Facing-Down_100x100xCR.jpg'
name: 'Barnaby Walters'
name: 'Just added some more tunes to http://www.waterpigs.co.uk/wpsm/ — As far as I can tell, it''s the largest collection of hurdy gurdy sheet music on the web! #folkmusic #hurdygurdy #abc'
content: "<p>Just added some more tunes to <a class=\"auto-link\" href=\"http://www.waterpigs.co.uk/wpsm/\">http://www.waterpigs.co.uk/wpsm/</a> — As far as I can tell, it's the largest collection of hurdy gurdy sheet music on the web! <a rel=\"tag\" href=\"/tags/folkmusic\">#folkmusic</a> <a rel=\"tag\" href=\"/tags/hurdygurdy\">#hurdygurdy</a> <a rel=\"tag\" href=\"/tags/abc\">#abc</a></p>\n"
published: '2011-09-16T16:41:38+00:00'
updated: null
<xml id="skufilterbrowse" class="slide">
<productcatalog><labels><label key="skuset.deliverypolicyurl">Delivery policy content URL</label><label key="price.save">Save</label><label key="skuset.seemoredetails">See more details</label><label key="price.additionaloffers">Additional Offers</label><label key="price.freeitem">Includes Free Item*</label><label key="price.instsaving">Instant Savings</label><label key="skuset.eddieseedetails">See details </label><label key="price.rebateurl">RebateURL</label><label key="skuset.freedelivery">FREE SHIPPING, plus 5% back for Rewards Members</label><label key="price.printableCoupons">Click here for Printable Coupon</label><label key="price.value">Value</label><label key="skuset.eddieshipdetails">Estimated to arrive no later than </label><label key="price.qty">Qty.</label><label key="price.chooseyouritems">Choose your Items</label><label key="price.true">true</label><label key="skuset.clearancemessage">&lt;strong&gt;CLEARANCE ITEM:&lt;/strong&gt; </label><label key="price
@barnabywalters
barnabywalters / uniquely_observed_species.py
Last active May 14, 2021 10:06
Find which species in an iNaturalist export only have observations from a single observer.
# coding: utf-8
import argparse
import pandas as pd
"""
Find which species in an iNaturalist export only have observations from a single observer.
Get an export from here: https://www.inaturalist.org/observations/export with a query such
as quality_grade=research&identifications=any&rank=species&projects[]=92926 and at least the
@barnabywalters
barnabywalters / album.html
Created May 18, 2021 09:36
mf2 Album Markup
<div class="h-entry">
<h1 class="p-name">Album Name</h1>
<time class="dt-published">2021-02-12</time>
<img class="u-photo" src="cover.png" alt="" />
<p class="p-summary">Summary of what the ablum is</p>
<div class="e-content">
file: 2021-06-timberlake.csv
# context_query is used to provide context for links to lists of observations when there’s no inat project providing that context.
# If you do have a project with date and place bounds, leave out context_query and use
# project: your-project-id
# instead.
context_query: 'd1=2021-06-11&amp;d2=2021-06-13&amp;place_id=118103'
locale: en
root_header_level: 2
places:
# Places MUST be in smallest to biggest order, id: global MUST be last in list.