Skip to content

Instantly share code, notes, and snippets.

Avatar
😃

David Wells DavidWells

😃
View GitHub Profile
View open-color-postcss-variables.js
// via https://yeun.github.io/open-color/
const palette = {
dark: [
'#d5d7e0',
'#acaebf',
'#8c8fa3',
'#666980',
'#4d4f66',
'#34354a',
@DavidWells
DavidWells / package.json
Created Sep 12, 2021
Symlink a directory for package.json scripts
View package.json
{
"if-not-ci": "pnpm ts support/scripts/run-if-not-ci.ts",
}
@DavidWells
DavidWells / javascript-highlight-text.js
Created Sep 10, 2021
Highlight Search match in JS
View javascript-highlight-text.js
function highlightMatch(string, regexp) {
return escapeString(string).replace(regexp, (match) => `<mark>${match}</mark>`)
}
// Used to match HTML entities and HTML characters.
const unescapedHtml = /[&<>"']/g
const hasUnescapedHtml = RegExp(unescapedHtml.source)
const htmlEscapes = {
'&': '&amp;',
@DavidWells
DavidWells / appendArguments.js
Last active Aug 1, 2021
Automagically append arguments to function calls or add to `this` within function
View appendArguments.js
/* Append arguments to functions */
function appendArguments(fn, append, context) {
if (!append) return fn
// console.log('context', context)
return function () {
/* Original args */
const args = Array.prototype.slice.call(arguments)
// console.log('original args', arguments)
/* Create clone of args */
@DavidWells
DavidWells / package.json
Created Jul 26, 2021
Passing multiple args to npm-run-all. "npm run test --email=foo --pw=foo --stage=foo"
View package.json
{
"scripts": {
"test": "npm-run-all 'test:* -- {1}'",
"test:unit": "ava --config ./_tests-unit.cjs",
"test:integration": "ava --config ./_tests-integration.cjs -- --email=$npm_config_email --pw=$npm_config_pw --stage=$npm_config_stage",
}
}
@DavidWells
DavidWells / package.json
Created Jul 21, 2021
Download repo via package.json scripts. Remove $GH_DOWNLOAD_TOKEN if public repo. `npm run download`
View package.json
{
"scripts": {
"predownload": "rimraf ./tmp-folder && rimraf ./folder && mkdirp ./folder",
"download": "curl -H \"Authorization: token $GH_DOWNLOAD_TOKEN\" -L https://api.github.com/repos/repo/repoName/zipball/master > repo.zip",
"postdownload": "unzip -q -d ./tmp-folder repo.zip && cd tmp-folder && mv `ls` repo && mv `ls` ../folder && echo 'repo downloaded!'",
}
}
@DavidWells
DavidWells / message.md
Created Jun 29, 2021
Does the new variable setup still allow for me to reference `AWS::`, `Params` & resources with `${}`?
View message.md
@DavidWells
DavidWells / regex-find-image-links-in-markdow.js
Created Jun 24, 2021
Find images in markdown file Regex
View regex-find-image-links-in-markdow.js
@DavidWells
DavidWells / validate-post-data.js
Created Jun 23, 2021
Validate markdown post details
View validate-post-data.js
const fs = require('fs')
const path = require('path')
const matter = require('gray-matter')
const outdent = require('outdent')
const { promisify } = require('util')
const { globby } = require('markdown-magic')
const authorDirectory = path.join(__dirname, 'authors')
const postsDirectory = path.join(__dirname, 'posts')
const dateFormatRegex = /[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])-/g
@DavidWells
DavidWells / claim-netlify-site.js
Created May 25, 2021
Anonymous claiming of netlify sites
View claim-netlify-site.js
const jwt = require('jsonwebtoken')
const {
NETLIFY_OAUTH_CLIENT_ID,
NETLIFY_OAUTH_CLIENT_SECRET
} = process.env
/* Function to handle netlify auth callback */
module.exports.handler = async (event, context) => {
const body = JSON.parse(event.body)
const { sessionId } = body