Skip to content

Instantly share code, notes, and snippets.

View derickwarshaw's full-sized avatar

Derick Warshaw derickwarshaw

  • Tampa, Florida
View GitHub Profile
@derickwarshaw
derickwarshaw / createDeferred.ts
Created October 9, 2019 02:06 — forked from compulim/createDeferred.ts
Deferred in ES6 Promise
interface IDeferred<T> {
promise: () => Promise<T>,
resolve: (result: T) => void,
reject: (error: Error) => void
}
function createDeferred<T>(): Promise<IDeferred<T>> {
return new Promise<IDeferred<T>>(resolveCreate => {
const promise = new Promise<T>(function (resolve, reject) {
resolveCreate({ promise: () => promise, resolve, reject });
@derickwarshaw
derickwarshaw / index.js
Created June 14, 2018 08:41 — forked from cereallarceny/index.js
Server-side rendering in Create React App
const md5File = require('md5-file');
const path = require('path');
// CSS styles will be imported on load and that complicates matters... ignore those bad boys!
const ignoreStyles = require('ignore-styles');
const register = ignoreStyles.default;
// We also want to ignore all image requests
// When running locally these will load from a standard import
// When running on the server, we want to load via their hashed version in the build folder
@derickwarshaw
derickwarshaw / regen-domain-types.js
Created June 14, 2018 01:47 — forked from adamkl/regen-domain-types.js
Generating typescript definitions from .graphql files using apollo-codegen and graphql-code-generator
const { introspectSchema } = require("apollo-codegen");
const { executeWithOptions } = require("graphql-code-generator/dist/cli");
const fs = require("fs");
const path = require("path");
const graphqlPath = "./src/graphql/";
const schemaInput = "./src/graphql/temp.graphql";
const jsonOutput = "./src/graphql/temp.json";
const dtsOutput = "./src/graphql/domain.d.ts";
@derickwarshaw
derickwarshaw / array_iteration_thoughts.md
Created March 16, 2018 10:52 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

@derickwarshaw
derickwarshaw / AsyncComponent.jsx
Created March 16, 2018 10:50 — forked from lencioni/AsyncComponent.jsx
<AsyncComponent> at Airbnb used for Webpack code splitting
// Usage:
//
// function loader() {
// return new Promise((resolve) => {
// if (process.env.LAZY_LOAD) {
// require.ensure([], (require) => {
// resolve(require('./SomeComponent').default);
// });
// }
// });
@derickwarshaw
derickwarshaw / README.md
Created October 30, 2017 07:31 — forked from dominikwilkowski/README.md
Ubuntu 16.04 setup with NGINX http/2 and letsencrypt

Intro

This is a basic collection of things I do when setting up a new headless ubuntu machine as a webserver. Following the steps below should give you a reasonable secure server with HTTP/2 support (including ALPN in chrome) and the fast NGINX server. I am happy to add things so leave a comment.

Basics

After creating the server (droplet on DigitalOcean) log in with