Skip to content

Instantly share code, notes, and snippets.

View stoutlabs's full-sized avatar
📡
Working from home...

Daniel Stout stoutlabs

📡
Working from home...
View GitHub Profile
// strip tags from HTML string
let strippedString = originalString.replace(/(<([^>]+)>)/gi, "");
// remove any duplicates from an array of primitives.
const unique = [...new Set(arr)];
// shuffle Array
const shuffleArray = (arr) => arr.sort(() => Math.random() - 0.5);
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
console.log(shuffleArray(arr));
@stoutlabs
stoutlabs / my-slugify.js
Last active October 8, 2021 20:23
Slugify Fn
export const slugify = string => {
const a =
"àáâäæãåāăąçćčđďèéêëēėęěğǵḧîïíīįìłḿñńǹňôöòóœøōõőṕŕřßśšşșťțûüùúūǘůűųẃẍÿýžźż·/_,:;";
const b =
"aaaaaaaaaacccddeeeeeeeegghiiiiiilmnnnnoooooooooprrsssssttuuuuuuuuuwxyyzzz------";
const p = new RegExp(a.split("").join("|"), "g");
return string
.toString()
.toLowerCase()
@stoutlabs
stoutlabs / useClientRect.js
Created September 11, 2021 09:17
React Hook: useClientRect (Works with SSR/SSG and React v17.0.2)
import { useState, useCallback } from "react";
import useLayoutEffect from "hooks/useIsomorphicLayoutEffect";
function getDimensionObject(node) {
if (node.getBoundingClientRect) {
const rect = node.getBoundingClientRect();
return {
width: rect.width,
height: rect.height,
@stoutlabs
stoutlabs / countryNamesCodes.json
Last active March 26, 2020 05:31
ISO Names/Codes
[
{
"Name": "Afghanistan",
"cca2": "AF",
"cca3": "AFG",
"ccn3": 4
},
{
"Name": "Albania",
"cca2": "AL",
@stoutlabs
stoutlabs / .gitignore
Created September 23, 2019 10:38
Node gitignore boilerplate
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
@stoutlabs
stoutlabs / dockerfile_multi_step
Created April 17, 2019 00:17
An example of a multi step Dockerfile
# build environment
FROM node:10.15.3-alpine as builder
WORKDIR /usr/src/app
ENV PATH /usr/src/app/node_modules/.bin:$PATH
COPY ./package.json ./
RUN npm install
COPY . .
RUN npm run build
# production environment
@stoutlabs
stoutlabs / oneliners.js
Created April 1, 2019 16:59 — forked from mikowl/oneliners.js
👑 Awesome one-liners you might find useful while coding.
// By @coderitual
// https://twitter.com/coderitual/status/1112297299307384833
// Remove any duplicates from an array of primitives.
const unique = [...new Set(arr)]
// Sleep in async functions. Use: await sleep(2000).
const sleep = (ms) => (new Promise(resolve => setTimeout(resolve, ms)));
// Type this in your code to break chrome debugger in that line.
@stoutlabs
stoutlabs / Dockerfile
Last active October 15, 2020 21:41
Simple Dockerfile for GatsbyJS (and NextJS)
FROM node:alpine
EXPOSE 8000 9929 9230
RUN \
apk add --no-cache python make g++ && \
apk add vips-dev fftw-dev --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing --repository http://dl-3.alpinelinux.org/alpine/edge/main && \
rm -fR /var/cache/apk/*
RUN npm install -g gatsby-cli yarn
WORKDIR /app