Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am davidmerfield on github.
  • I am davidmerfield (https://keybase.io/davidmerfield) on keybase.
  • I have a public key ASDwQIJcpHRvFNAgLyNGk9DKNi1flvFiZTMABfMhcAILowo

To claim this, I am signing this object:

@davidmerfield
davidmerfield / sort.js
Last active July 8, 2019 15:54
sorts DOM nodes by an attribute, alphabetically.
<script type="text/javascript">
// e.g. <span data-path="/foo" class="sort-me">...</span>
var attributeToSort = 'data-path';
var selector = '.sort-me';
var zero="0".charCodeAt(0);function isWhitespace(i){return i<=32}function isDigit(i){return 48<=i&&i<=57}var compare=function(i,r){for(var t,e,f,n,o,u,s,a,c=0,h=0,g=i.length,D=r.length;c<g&&h<D;){for(t=i.charCodeAt(c),e=r.charCodeAt(h),f=n=0,o=u=0,s=!0,a=0;isWhitespace(t);)c+=1,t=i.charCodeAt(c);for(;isWhitespace(e);)h+=1,e=r.charCodeAt(h);if(isDigit(t)&&!isDigit(e))return-1;if(!isDigit(t)&&isDigit(e))return 1;if(!s)return-1;for(0;t===zero;)f+=1,c+=1,t=i.charCodeAt(c);for(;e===zero;)n+=1,h+=1,e=r.charCodeAt(h);for(;isDigit(t)||isDigit(e);)isDigit(t)&&isDigit(e)&&0===a&&(s?t<e?a=-1:t>e&&(a=1):t>e?a=-1:t<e&&(a=1)),isDigit(t)&&(c+=1,o+=1,t=i.charCodeAt(c)),isDigit(e)&&(h+=1,u+=1,e=r.charCodeAt(h));if(s){if(o<u)return-1;if(o>u)return 1}else{if(o>u)return-1;if(o<u)return 1}if(a)return a;if(s){if(f>n)return-1;if(f<n)return 1}else{if(f<n)return-1;if(f>n)return 1}if
@davidmerfield
davidmerfield / photos.html
Created May 17, 2019 14:49
Page listing all the photos in every post on Blot
<!DOCTYPE html>
<html>
<title>{{title}}</title>
{{> head}}
<body>
{{> header}}
<style type="text/css">
#photos {display: flex;flex-wrap: wrap;align-items: center;justify-content: center}
#photos a {width: 33.3333%;padding: 1em;flex-shrink: 1;flex-grow: 1;box-sizing: border-box;background: none;}
.pre-loaded {visibility: hidden;opacity: 0;will-change: opacity;transition: opacity .3s, visibility .3s;}
@davidmerfield
davidmerfield / photos.html
Created May 16, 2019 01:04
Photos page on Blot
<!DOCTYPE html>
<html>
{{> head}}
<body>
{{> header}}
<style type="text/css">
#photos {display:flex;flex-wrap:wrap;align-items:center;justify-content:center}
#photos a {width:33.3333%;padding:1em;flex-shrink:1;flex-grow:1;box-sizing:border-box;background:none;}
</style>
<div class="container">
// CSS selector which will match all the HTML elements containing a date
var dateSelector = '.date';
// Iterate over all the dates, hiding each date identical to its immediate predeccessor
Array.from(document.querySelectorAll(dateSelector)).reduce(function(previousDate, el){
if (previousDate && previousDate === el.innerHTML)
el.style.display='none';
return el.innerHTML;
}, '');
@davidmerfield
davidmerfield / feed.rss
Last active March 29, 2019 14:50
RSS feed which improves the display of images on Micro.blog
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
<channel>
<title><![CDATA[ {{{title}}}]]></title>
<link>{{{blogURL}}}</link>
<atom:link href="{{{blogURL}}}/feed.rss" rel="self" type="application/rss+xml"/>
<description><![CDATA[ The feed of updates to {{{title}}} ]]></description>
{{#recentEntries}}
<item>
<title>{{#titleTag}}<![CDATA[ {{{title}}} ]]>{{/titleTag}}</title>
@davidmerfield
davidmerfield / wordpress.xml
Created February 6, 2019 00:16
A view for a Hugo site to generate a Wordpress export file
<?xml version="1.0" encoding="UTF-8" ?>
<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
<!-- It contains information about your site's posts, pages, comments, categories, and other content. -->
<!-- You may use this file to transfer that content from one site to another. -->
<!-- This file is not intended to serve as a complete backup of your site. -->
<!-- To import this information into a WordPress site follow these steps: -->
<!-- 1. Log in to that site as an administrator. -->
<!-- 2. Go to Tools: Import in the WordPress admin panel. -->
<!-- 3. Install the "WordPress" importer from the list. -->
var lower = 'acemnorsuvwxz'.split('');
var upper = '1234567890ABCDEFGHJKMNPRSTUVWXYZ'.split('');
var chars = lower;
var LEN = 12;
var PREFIX = 'site'; // site file post theme
function uid () {
var res = '';
while (res.length < LEN)
res += chars[Math.floor(Math.random()*chars.length)];
h1 a {
position:relative
}
h1 a:after {
content: "→";
position: absolute;
right: -1.333em;
top: 0;
line-height: 1.3;