Skip to content

Instantly share code, notes, and snippets.

View DavidWells's full-sized avatar
😃

David Wells DavidWells

😃
View GitHub Profile
@jonathantneal
jonathantneal / command.js
Last active October 26, 2022 07:20
Executable JavaScript Modules
":" //#;exec /usr/bin/env node --input-type=module - $@<$0
import process from 'process'
const { argv } = process
console.log(argv)
@kentcdodds
kentcdodds / index.js
Created July 9, 2021 21:40
Parsing HTML or Markdown and processing both as markdown then outputting to HTML
const unified = require('unified')
const parseMarkdown = require('remark-parse')
const parseHtml = require('rehype-parse')
const remark2rehype = require('remark-rehype')
const rehype2remark = require('rehype-remark')
const rehypeStringify = require('rehype-stringify')
const visit = require('unist-util-visit')
async function go() {
const inputString = `
@leegilmorecode
leegilmorecode / handler.js
Created June 27, 2021 14:29
Example of a lambda handler using the AWS AppConfig Lambda Layer Extension.
/* eslint-disable no-undef */
const axios = require("axios");
const {
STAGE: stage,
APPLICATION: application,
ENVIRONMENT: environment,
CONFIGURATION: configuration,
} = process.env;
@leegilmorecode
leegilmorecode / serverless.yml
Created June 27, 2021 14:26
Example of AWS AppConfig alongside the Serverless Framework for the use of Feature Flags
service: serverless-feature-flag
provider:
name: aws
runtime: nodejs12.x
lambdaHashingVersion: 20201221
memorySize: 128
stage: ${opt:stage, 'develop'}
region: eu-west-1
apiGateway:
shouldStartNameWithService: true
@emmiep
emmiep / graphql.config.js
Created May 27, 2021 14:29
VSCode next+graphql setup
/** @typedef {import("graphql-config").IGraphQLConfig} IGraphQLConfig */
const {loadEnvConfig} = require('@next/env');
loadEnvConfig(__dirname, true);
/** @type IGraphQLConfig */
const config = {
schema: process.env.GRAPHCMS_ENDPOINT,
extensions: {
@millsp
millsp / unionizeDeep.ts
Created May 17, 2021 17:43
Unionize Deep
type MarkUndefinable<A, B> = {
[K in keyof A]: A[K] extends O.Object
? MarkUndefinable<A[K], A.At<B, K>>
: K extends keyof B ? A[K] | undefined : A[K]
}
type UnionizeDeep<A extends object, B extends object> =
O.Merge<MarkUndefinable<A, B>, B, 'deep', M.BuiltIn, undefined>
type test = A.Compute<UnionizeDeep<{
@helabenkhalfallah
helabenkhalfallah / httpFifoRequestsExecutor.js
Last active March 9, 2022 02:24
Async Http Requests Executor (FiFo) using ES6 Generator
function httpFiFoRequestsExecutor({
onTaskSuccess,
onTaskFail,
}) {
async function* execute(taskInfos, props) {
const {
taskIdentifier,
taskFn
} = taskInfos || {};
try {
@kentcdodds
kentcdodds / diff.js
Created April 29, 2021 17:23
A git diff for EpicReact workshops
const {spawnSync} = require('child_process')
const inquirer = require('inquirer')
const glob = require('glob')
async function go() {
const files = glob
.sync('src/+(exercise|final)/*.+(js|ts|tsx)', {
ignore: ['*.d.ts'],
})
.map(f => f.replace(/^src\//, ''))
@wlib
wlib / LICENSE
Last active April 30, 2024 17:07
Run a shell script with bash, line-by-line, prompted on each command. Useful for running unknown scripts or debugging. Not a secure substitute for understanding a script beforehand.
MIT License
Copyright (c) 2021 Daniel Ethridge
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@jackrusher
jackrusher / trinity.js
Created March 29, 2021 09:23
A fast, minimal JS triple store implementation in ~70 lines of code
// three indices to efficiently support all lookups
function createDB() {
return {eav: new Map(),
ave: new Map(),
vea: new Map()};
}
function addToIndex(xs, x, y, z, triple) {
let ys = xs.get(x);
if(ys == undefined) {