Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢
Moving slowly and fixing things

Paul Robert Lloyd paulrobertlloyd

🐢
Moving slowly and fixing things
View GitHub Profile
@paulrobertlloyd
paulrobertlloyd / gist:8189506
Last active Jan 1, 2016
grunt-contrib-uglify is borking my JavaScript. What am I doing wrong?
View gist:8189506
/**
* 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 {
@paulrobertlloyd
paulrobertlloyd / Rakefile
Last active Aug 29, 2015
Rake task to concatenate CSS files
View Rakefile
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 / Rakefile
Last active Aug 29, 2015
Iterate though matched patterns in document, perform a function on each match, and write result to file
View Rakefile
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 / figure.html
Created Jan 9, 2015
Custom Liquid tag block to render a figure with optional caption
View figure.html
<!-- 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 / Directory structure
Created May 8, 2015
[gulp-sass] no mixin named red
View Directory structure
# src/base/scss/
- base.scss
- helpers/
- mixins.scss
- variables.scss
# src/components/button/
- button.scss
@paulrobertlloyd
paulrobertlloyd / context.json
Last active Aug 3, 2019
Looping over values with Nunjucks. Some values are strings, some values are arrays. Now what?
View context.json
{
"items": [
{
"name": "Last modified time",
"value": "2004-12-23T23:33Z"
},
{
"name": "Recommended update interval",
"value": "60s"
},
@paulrobertlloyd
paulrobertlloyd / index.html
Created May 9, 2018
Andy Dennis’ function introduction
View index.html
<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 / 1-defaultConfig.js
Last active Mar 2, 2019
Merging two object arrays?
View 1-defaultConfig.js
'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 }}'
}
}, {
View diff.html
<!doctype html>
<html lang="en-gb" prefix="og: http://ogp.me/ns#">
<head>
<meta charset="utf-8">
<meta property="og:title" content="404">
<meta property="og:description" name="description" content="There’s nothing useful here. Sorry about that.">
<meta property="og:url" content="/404">
<meta property="og:image" content="/images/app.png">
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="@paulrobertlloyd">
@paulrobertlloyd
paulrobertlloyd / routes.js
Last active Oct 1, 2019
Express application routes - Authentication using IndieAuth
View routes.js
// Express
const express = require('express');
const router = new express.Router();
// IndieAuth
const IndieAuth = require('indieauth-helper');
const auth = new IndieAuth({
secret: 'topSecretString'
});