Skip to content

Instantly share code, notes, and snippets.

@barnabywalters
barnabywalters / style.css
Created September 5, 2012 19:22
em based responsive line lengths with cascading breakpoints and stuff
/*
* The basic idea:
* No more "mobile first", just take up the entire browser width when
* optimum line length gets near viewport width.
*/
body
{
width: 100%;
}
<?php
$render = function ($_path, $data) {
extract($data);
unset($data);
require $_path;
};
ob_start();
$render($_path, $data);
<?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
{
"alternates": [
{
"url": "http://example.org",
"rel": "home",
"media": "screen",
"hreflang": "en"
}
],
"rels":
@barnabywalters
barnabywalters / input.html
Last active December 17, 2015 21:18
Test case for microformats-2 e-* p-* HTML injection potential security hole
<span class="h-thing">
<span class="e-content">&lt; Things &gt; &amp;</span>
</span>
<span class="h-thing">
<span class="p-content">&lt; Things &gt; &amp;</span>
</span>
@barnabywalters
barnabywalters / notes.web
Last active December 20, 2015 20:09
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`
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
barnabywalters / opd.js
Last active December 21, 2015 23:09
Original Post Discovery minimal client side implementation. Requires promisejs (HTTP) and bean (events)
// 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 = event.target.value;
// TODO: Start loading indicator
promise.get('/services/original-post', {'url': url}).then(function (error, text, xhr) {
@barnabywalters
barnabywalters / barnabywalters.json
Created November 7, 2013 16:27
HTML from https://twitter.com/barnabywalters, parsed using indieweb/php-mf2-shim as of 2012-11-07
{
"rels": {
"shortcut": [
"https:\/\/abs.twimg.com\/favicons\/favicon.ico"
],
"icon": [
"https:\/\/abs.twimg.com\/favicons\/favicon.ico"
],
"canonical": [
"https:\/\/twitter.com\/BarnabyWalters"
@barnabywalters
barnabywalters / template.php
Created November 21, 2013 20:57
Dumbest PHP template rendering function ever
<?php
function renderTemplate($template, array $__templateData = array()) {
$render = function ($__path, $render=null) use ($__templateData) {
ob_start();
extract($__templateData);
unset($__templateData);
include __DIR__ . '/../templates/' . $__path . '.php';
return ob_get_clean();
};
<?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, '/');