Skip to content

Instantly share code, notes, and snippets.

David Wells DavidWells

Block or report user

Report or block DavidWells

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
DavidWells /
Created Feb 15, 2020
Don Norman quote from The Invisible Computer

Don Norman quote from The Invisible Computer:

"Don’t ask people what they want. Watch them and figure out their needs. If you ask, people usually focus on what they have and ask for it to be better: cheaper, faster, smaller. A good observer might discover that the task is unnecessary, that it is possible to restructure things or provide a new technology that eliminates the painstaking parts of their procedures. If you just follow what people ask for, you could end up making their lives even more complicated."

View aws-resource-tags-example.yml
- Key: Name
Value: ${self:custom.analysis-tablename}
- Key: Environment
Value: ${self:custom.stage}
- Key: Project
Value: ${}
- Key: Application
Value: ${self:custom.service_acronym}
DavidWells / component.js
Last active Jan 22, 2020
Use proxies in dev to guard against potentially missing styles. Also use linting & stuff for warning etc. This is handy for ensuring style refactors don't result in undefined class names. Now a package
View component.js
import React from "react"
import { Link } from "react-router-dom"
import styleGuard from './style-guard'
import css from './styles.css'
const styles = styleGuard(css)
export default function NavBar(props) {
const { auth, handleLogout } = props
return (
DavidWells / getFunctionArgsByName.js
Last active Dec 15, 2019
getFunctionArgsByName will return the argument key names. Careful using with minification
View getFunctionArgsByName.js
function getFunctionArgsByName(func) {
return (func + '')
.replace(/[/][/].*$/mg,'') // strip single-line comments
.replace(/\s+/g, '') // strip white space
.replace(/[/][*][^/*]*[*][/]/g, '') // strip multi-line comments
.split('){', 1)[0].replace(/^[^(]*[(]/, '') // extract the parameters
.replace(/=[^,]+/g, '') // strip any ES6 defaults
.split(',').filter(Boolean); // split & filter [""]
DavidWells /
Last active Dec 16, 2019
Netlify Plugin Spec

Simple plugin

Here is a simple plugin with no config and it runs on a single lifecycle event postBuild

// Plugin code
DavidWells / get-npm-download-count.js
Created Nov 9, 2019
Get npm download count by period
View get-npm-download-count.js
const path = require('path')
const fetch = require('node-fetch')
const flatcache = require('flat-cache')
/* Download API
period: Joi.string().regex(/(\d{4}-\d{2}-\d{2}(:\d{4}-\d{2}-\d{2})?|[\w-]+)/).required(),
Package "package-name", last week:
Package "package-name", given 7-day period:
DavidWells /
Last active Nov 3, 2019
Tiny tiny markdown text

How to make tiny text in markdown

Normal text here. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vitae mauris arcu, eu pretium nisi. Vivamus vitae mi ligula, non hendrerit urna. Suspendisse potenti. Quisque eget massa a massa semper mollis.

Tiny text is here. Awwwww its so cuteeeeeeeeeee

Normal big text

View semver-regex.js
// NUM . NUM . NUM -beta.3.4 (optional) (ignore)
var SEMVER = /^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[\da-z-]+(?:\.[\da-z-]+)*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?$/i
var SIMPLE_NUMBER = /^(0|[1-9][0-9]*)$/
function semverCmp(ver1, ver2) {
if (ver1 === ver2) return 0
var match1 = ver1.match(SEMVER), match2 = ver2.match(SEMVER)
if (!match1) return match2 ? 1 : 0
if (!match2) return -1
for (var i = 1; i <= 3; i++) {
DavidWells / app-code.js
Last active Oct 3, 2019
Example of using analytics + a plugin (or listener) to send campaign data to a backend serverless function
View app-code.js
import Analytics from 'analytics'
// Listen for ?utm params and send data to Netlify function
const customUtmTokenPlugin = {
NAMESPACE: 'save-campaign-data',
campaign: ({ payload }) => {
const { campaign } = payload
console.log('utm data', campaign)
fetch('/.netlify/functions/save-campaign-data', {
method: 'POST',
You can’t perform that action at this time.