Skip to content

Instantly share code, notes, and snippets.

@OliverJAsh
OliverJAsh / foo.js
Last active October 22, 2021 09:45
Async iterators with map, skipWhile, and takeUntil
class FunctifiedAsync {
constructor(iterable) {
this.iterable = iterable;
}
async *[Symbol.asyncIterator]() {
for await (const value of this.iterable) {
yield value;
}
}
@vlucas
vlucas / encryption.ts
Last active June 3, 2025 10:38
Stronger Encryption and Decryption in Node.js
import { createCipheriv, createDecipheriv, randomBytes } from "crypto";
const ENCRYPTION_KEY: string = process.env.ENCRYPTION_KEY || ""; // Must be 256 bits (32 characters)
const IV_LENGTH: number = 16; // For AES, this is always 16
/**
* Will generate valid encryption keys for use
* Not used in the code below, but generate one and store it in ENV for your own purposes
*/
export function keyGen() {
@redblobgames
redblobgames / drop-shadow.html
Created March 8, 2017 00:48
SVG drop shadow example
<!DOCTYPE html>
<html>
<svg width="80%" height="80%" viewBox="-100 -100 200 200">
<!-- Need this definition to make a drop shadow - based on examples from many articles, including svg spec -->
<defs>
<filter id="drop-shadow" x="-100%" y="-100%" width="300%" height="300%">
<feGaussianBlur in="SourceAlpha" stdDeviation="2"/>
<feOffset dx="5" dy="5" result="offsetblur"/>
<feFlood flood-color="#000000"/>
@singledigit
singledigit / cognito.yaml
Last active September 20, 2025 17:27
Create a Cognito Authentication Backend via CloudFormation
AWSTemplateFormatVersion: '2010-09-09'
Description: Cognito Stack
Parameters:
AuthName:
Type: String
Description: Unique Auth Name for Cognito Resources
Resources:
# Creates a role that allows Cognito to send SNS messages
SNSRole:
@martypdx
martypdx / mjs.sh
Last active October 16, 2021 09:02
# rename all .js to .mjs
for f in **/*.js; do mv -- "$f" "${f%.js}.mjs"; done
# add .mjs to all file-based import statements*
find . -type f -name "*.mjs" -exec sed -i '' -E "s/(import.+'\.[a-zA-Z0-9\.\/-]+)';/\1\.mjs';/g" {} \;
# *NOTES:
# 1. This will double up existing .mjs extension in imports.
# Couldn't get phrase negation working in this sed substitution regex :(
#
@kentcdodds
kentcdodds / index.html
Last active June 24, 2021 19:48
The one true react boilerplate
<body>
<div id="⚛️"></div>
<script src="https://unpkg.com/[email protected]/umd/react.development.js"></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/[email protected]/babel.js"></script>
<script type="text/babel">
ReactDOM.render(<div>Hello World!</div>, document.getElementById('⚛️'))
</script>
</body>
const { buildClientSchema, printSchema } = require("graphql");
const fs = require("fs");
const introspectionSchemaResult = JSON.parse(fs.readFileSync("result.json"));
const graphqlSchemaObj = buildClientSchema(introspectionSchemaResult);
const sdlString = printSchema(graphqlSchemaObj);
@cabecada
cabecada / gist:da8913830960a644755b18a02b65e184
Last active January 14, 2025 16:00
python postgres connection with retry example
#!/usr/bin/env python
#https://github.com/psycopg/psycopg2/issues/261
import psycopg2
ISOLEVEL = psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT
import time
@alfonmga
alfonmga / apollo-refreshToken-link.js
Last active September 5, 2023 22:29
Apollo refresh auth token link. It tries to refresh the user access token on the fly when API throws out an UNAUTHENTICATED error. If multiple requests fail at the same time, it queues them to re-try them later if we are able to get a new access token, otherwise we log out the user and redirect him to the login page.
@sibelius
sibelius / react-scripts+3.0.1.patch
Created July 22, 2019 00:51
react-scripts patch-package to avoid type checking on CRA
diff --git a/node_modules/react-scripts/config/webpack.config.js b/node_modules/react-scripts/config/webpack.config.js
index 8f70442..dfd86d8 100644
--- a/node_modules/react-scripts/config/webpack.config.js
+++ b/node_modules/react-scripts/config/webpack.config.js
@@ -47,6 +47,10 @@ const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
// Check if TypeScript is setup
const useTypeScript = fs.existsSync(paths.appTsConfig);
+// Skip TypeScript type checking
+const typeCheckTypeScript =