Skip to content

Instantly share code, notes, and snippets.

@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 =
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);
@n1ru4l
n1ru4l / use-reset-State.js
Created August 30, 2019 07:02
useResetState
const NO_VALUE_SYMBOL = Symbol("USE_RESET_STATE_NO_VALUE");
const useResetState = (createValue, deps = []) => {
const [, triggerRerender] = useState(createValue);
const stateRef = useRef(NO_VALUE_SYMBOL);
const depsRef = useRef(deps);
if (stateRef.current === NO_VALUE_SYMBOL) {
stateRef.current = createValue();
}
if (depsRef.current.some((value, index) => value !== deps[index])) {
@alloy
alloy / LiveQueryPolyfill.ts
Last active February 24, 2021 15:09
Rewrite GraphQL Live Query to subscription.
/**
* This is a Live Query polyfill, as graphql-js does not strictly have support for that. Instead, we leave it up to the
* client to recognize a Live Query is requested with the `@live` directive on a `query` operation and here we
* transform it into a `live` subscription instead.
*
* Consider a schema like the following:
*
* ```graphql
type Badge {
id: ID!
@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/react@16.0.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16.0.0/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6.26.0/babel.js"></script>
<script type="text/babel">
ReactDOM.render(<div>Hello World!</div>, document.getElementById('⚛️'))
</script>
</body>
@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 :(
#
@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;
}
}
@sibelius
sibelius / Environment.tsx
Last active October 7, 2022 23:07
Debug Relay Store on Chrome DevTools
const env = new Environment({
network,
store,
handlerProvider: RelayDefaultHandlerProvider,
log: isDev ? relayTransactionLogger : null,
});
if (isDev) {
window.relayEnvironment = env;
window.debugRelayStore = () =>
@adrianorsouza
adrianorsouza / mkselfssl.sh
Last active September 1, 2023 10:34
Script to create a new self-signed SSL Certificate for Nginx
#!/bin/bash
# @author Adriano Rosa (http://adrianorosa.com)
# @date: 2014-05-13 09:43
#
# Bash Script to create a new self-signed SSL Certificate
# At the end of creating a new Certificate this script will output a few lines
# to be copied and placed into NGINX site conf
#
# USAGE: this command will ask for the certificate name and number in days it will expire
@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.