Skip to content

Instantly share code, notes, and snippets.

@brandonsheppard
brandonsheppard / worker.js
Created May 31, 2020 00:14
Redirect to naked domain — Cloudflare Worker
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const pageURL = new URL(request.url);
return Response.redirect(`${pageURL.protocol}//${String(pageURL.host).substring(4)}${pageURL.pathname}${pageURL.search}`)
}
@brandonsheppard
brandonsheppard / how.md
Created September 5, 2019 23:11
Sum and search by content and date (parsed) in Google visual query language
=iferror(sum(query(Transactions!$A:$F,"select D where B contains '"&$A11&"' and A = date '"&text(F$1,"yyyy-mm-dd")&"'")))
@brandonsheppard
brandonsheppard / gist:89476f18fbb6a3f4c6ed0190e2e28395
Created March 18, 2019 06:34
Find all cached sub-pages in web.archive.org
https://web.archive.org/web/*/URL/*

e.g.,

https://web.archive.org/web/*/https://github.com/NetoECommerce/Skeletal/*
@brandonsheppard
brandonsheppard / gist:8e9b40a4be8462e0c68452adc4835404
Created November 12, 2018 21:04
Conditional format — highlight last month
=date(year(edate(today(),-1)),MONTH(edate(today(),-1)),1)
// assumes date in cell is the 1st
@brandonsheppard
brandonsheppard / how.md
Last active December 28, 2017 04:55
Format release notes MD from JSON.

formatNotes()

Pass commit data into this function to format a markdown commit note. Data structure is based on what Github's compare endpoint returns.

This is useful for generating a changelog for release notes based on git activity.

Example data:

Based on response from Github's compareCommits endpoint.

@brandonsheppard
brandonsheppard / how.md
Created December 28, 2017 04:51
Generate chronological version number based on previous version number

generateVersionNumber()

This function generates a date-based version number. Year + Month + Iteration

So, the first release in March 2017 will be 17.3.0

If multiple releases occur in a month, the final number will increase. Otherwise, an entirely new verion number will be generated.

i.e.

@brandonsheppard
brandonsheppard / demo.js
Last active November 23, 2017 23:46
Simple form event logging with Performance Web API and jQuery
// Run on page load
$('input').on('focus blur',function(e){
performance.mark(e.type+ ' ' + e.target.name)
});
// Run to see results
console.table(performance.getEntriesByType('mark'))
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.log(mutation.type);
});
});
observer.observe(document.getElementById('bill_selector'), {
attributes: true,
childList: true,
characterData: true
@brandonsheppard
brandonsheppard / 1.how.html
Created August 10, 2016 05:03
Show a modal to query the shoppers country if they aren't in Australia
<div class="modal fade" id="shipCountryModal" tabindex="-1" role="dialog" aria-labelledby="shipCountryModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<form method="post" action="[@url@]">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Hello, international shopper!</h4>
</div>
<div class="modal-body">
<p>It looks like you're not shopping from Australia, where we are based&mdash;select your country below and we'll ensure you're not seeing prices which include Australia-specific taxes.</p>
@brandonsheppard
brandonsheppard / how.md
Created July 26, 2016 05:45
How to use $.nShowActivity('.nactivity')

You need to add a FontAwesome loader to this div. There are a list of options here.

You then simply need to run the function when you need the loader to display:

$.nShowActivity('.nactivity')