Skip to content

Instantly share code, notes, and snippets.

View paulrobertlloyd's full-sized avatar
🐢
Moving slowly and fixing things

Paul Robert Lloyd paulrobertlloyd

🐢
Moving slowly and fixing things
View GitHub Profile
@paulrobertlloyd
paulrobertlloyd / wtf.md
Last active March 25, 2020 12:08
Different result via npm script and npx

If I use the following npm script:

"scripts": {
  "lint:markdown": "markdownlint app/**/*.md",
},

and run npm run lint:markdown, the glob only finds 5 files.

@paulrobertlloyd
paulrobertlloyd / routes.js
Last active October 1, 2019 07:35
Express application routes - Authentication using IndieAuth
// Express
const express = require('express');
const router = new express.Router();
// IndieAuth
const IndieAuth = require('indieauth-helper');
const auth = new IndieAuth({
secret: 'topSecretString'
});
@paulrobertlloyd
paulrobertlloyd / 1-defaultConfig.js
Last active March 2, 2019 18:35
Merging two object arrays?
'post-types': [{
type: 'article',
name: 'Article',
path: {
template: 'app/templates/article.njk',
post: '_posts/{{ published }}-{{ slug }}.md',
file: 'images/{{ published }}/{{ slug }}/{{ filename }}',
url: '{{ published }}/{{ slug }}'
}
}, {
@paulrobertlloyd
paulrobertlloyd / index.html
Created May 9, 2018 15:48
Andy Dennis’ function introduction
<html>
<body>
<a class="that" href="yippee.html">That link</a>
<script>
var foo = function () {
var $ = document.querySelector.bind(document)
var el = {
thatLink: $('a.that')
}
function addListeners () {
@paulrobertlloyd
paulrobertlloyd / context.json
Last active August 3, 2019 07:44
Looping over values with Nunjucks. Some values are strings, some values are arrays. Now what?
{
"items": [
{
"name": "Last modified time",
"value": "2004-12-23T23:33Z"
},
{
"name": "Recommended update interval",
"value": "60s"
},
@paulrobertlloyd
paulrobertlloyd / Directory structure
Created May 8, 2015 13:01
[gulp-sass] no mixin named red
# src/base/scss/
- base.scss
- helpers/
- mixins.scss
- variables.scss
# src/components/button/
- button.scss
@paulrobertlloyd
paulrobertlloyd / figure.html
Created January 9, 2015 21:26
Custom Liquid tag block to render a figure with optional caption
<!-- Arguments without quotes -->
<!-- ISSUE: Only content between first two quotes rendered -->
<figure class="figure class1"><div class="figure__main">
<p><img src="/assets/images/2008/12/chicago.jpg" alt="" /></p>
</div><figcaption class="figure__caption"><p>Cloud&nbsp;Gate</p>
</figcaption></figure>
<!-- Arguments with single quotes, regardless of content -->
<!-- ISSUE: Nothing generated if argument contains quotes -->
<figure class="figure class1 class2"><div class="figure__main">
@paulrobertlloyd
paulrobertlloyd / Rakefile
Last active August 29, 2015 14:07
Iterate though matched patterns in document, perform a function on each match, and write result to file
desc "Replace email addresses in remarks with md5 hashed strings"
task :hash do |t|
FileList.new('source/_data/remarks/*.yml').each do |path|
File.open(path, 'r+:utf-8') do |file_name|
require 'digest/md5'
private :hash
def hash(email)
email_address = email ? email.downcase.strip : ''
Digest::MD5.hexdigest(email_address)
@paulrobertlloyd
paulrobertlloyd / Rakefile
Last active August 29, 2015 14:05
Rake task to concatenate CSS files
destination = 'public'
source = 'source'
desc "Concatenate CSS files"
task :concatenate_css do
files = FileList["#{source}/**/*.css"]
concatenated_filename = "#{destination}/stylesheets/styles.css"
File.open(concatenated_filename, "w") do |output|
files.each do |input|
@paulrobertlloyd
paulrobertlloyd / gist:8189506
Last active January 1, 2016 19:19
grunt-contrib-uglify is borking my JavaScript. What am I doing wrong?
/**
* Before grunt-contrib-uglify
*/
(function(doc) {
if (document.querySelector) {
var toggleClassName = function(element, toggleClass) {
var reg = new RegExp('(\\s|^)' + toggleClass + '(\\s|$)');
if (!element.className.match(reg)) {
element.className += ' ' + toggleClass;
} else {