Skip to content

Instantly share code, notes, and snippets.

View Andy-set-studio's full-sized avatar

Andy Bell Andy-set-studio

View GitHub Profile
@Andy-set-studio
Andy-set-studio / service-worker.js
Created September 4, 2018 15:24
Bypass service worker on localhost
self.addEventListener('fetch', evt => {
// Define the hostnames that you want to ignore
const ignoredHosts = ['localhost'];
// Destructure the hostname out of the event's request URL by creating a new URL instance
const {hostname} = new URL(evt.request.url);
// Bail out if our definition contains this url
if (ignoredHosts.indexOf(hostname) >= 0) {
@Andy-set-studio
Andy-set-studio / .eslintrc VANILLA
Last active November 20, 2018 15:12
ESLint Base
{
"env": {
"browser": true,
"es6": true
},
"parserOptions": {
"parser": "babel-eslint",
"sourceType": "module"
},
"rules": {
@Andy-set-studio
Andy-set-studio / example.md
Created December 15, 2018 14:35
Filter posts by a passed year
title year layout
An example
2018
example.njk
@Andy-set-studio
Andy-set-studio / modify-unix-time.js
Last active January 6, 2019 14:11
🔥 A little JavaScript snippet here for if you want to modify a `Date` object and get back a Unix timestamp in seconds based on that modification.
/**
* Take a base date, modify it with passed options and return back the number of seconds since Epoch time
*
* @param {Object} [options={}] Options for what you want to modify, follows the following format: { hours: 0, minutes: 0, seconds: 0 }
* @returns {Number}
*/
const modifyUnixTime = (options = {}) => {
// Create our modifications object by merging a static base with the passed options
const modifications = Object.assign(
{ hours: 0, minutes: 0, seconds: 0 },
@Andy-set-studio
Andy-set-studio / index.php
Created January 11, 2019 12:20
Basic PHP example
<?php
$name = 'Andy';
$age = 31;
$favouriteTakeaways = ['Indian', 'Italian', 'Thai'];
$favouriteCodeLanguages = ['HTML', 'CSS', 'JavaScript', 'PHP'];
?>
<!doctype HTML>
<html>
<head>
@Andy-set-studio
Andy-set-studio / letter.txt
Created March 23, 2019 12:15
People’s March Letter
Dear Andrea Leadsom MP,
I won’t be able to travel to London today, but I would like to make it known that I support the People’s Vote March.
The “will of the people” has changed since 2016 and I hope this event will make this clear to you and your Government colleagues.
Sincerely,
Andrew Bell
@Andy-set-studio
Andy-set-studio / reset.css
Last active September 21, 2020 15:19
Minimal CSS reset
/* Box sizing rules */
* {
box-sizing: border-box;
}
*:before,
*:after {
box-sizing: inherit;
}
/**
* Pass in an element and its CSS Custom Property that you want the value of.
* Optionally, you can determine what datatype you get back.
*
* @param {String} propKey
* @param {HTMLELement} element=document.documentElement
* @param {String} castAs='string'
* @returns {*}
*/
const getCSSCustomProp = (propKey, element = document.documentElement, castAs = 'string') => {
@Andy-set-studio
Andy-set-studio / html.js
Last active August 10, 2024 20:59
HTML tagged template literal for syntax highlighting
const html = input => input;
@Andy-set-studio
Andy-set-studio / global.js
Created June 11, 2019 19:43
Cache busting with 11ty (stick global.js in _data folder)
module.exports = {
random() {
const segment = () => {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};
return `${segment()}-${segment()}-${segment()}`;
}
};