Skip to content

Instantly share code, notes, and snippets.

View marutypes's full-sized avatar
💻

Mallory Allen marutypes

💻
View GitHub Profile
@marutypes
marutypes / node-gc-debug-flags
Created October 29, 2018 14:38
node garbage collection tracing flags
--log_gc (Log heap samples on garbage collection for the hp2ps tool.)
type: bool default: false
--expose_gc (expose gc extension)
type: bool default: false
--trace_gc (print one trace line following each garbage collection)
type: bool default: false
--trace_gc_nvp (print one detailed trace line in name=value format after each garbage collection)
type: bool default: false
--trace_gc_ignore_scavenger (do not print trace line after scavenger collection)
type: bool default: false
const arrayEqual = (a: any[], b: any[]) => {
if (a.length !== b.length) return false
for (const index in a)
if (!deepEqual(a[index], b[index])) {
return false
}
return true
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
@marutypes
marutypes / Show me all the events
Created March 29, 2018 17:54
TFW you're debugging event heavy turbograft flows and you just want to know wtf is happening
const de = document.dispatchEvent.bind(document);
document.dispatchEvent = (event) => {
console.log(event.type)
return de(event)
}
interface Options {
pattern?: Regex
filter(path: string)?: boolean,
transform(path: string, content: string)?: string,
onSuccess(path): void,
onFail(path): void,
}
const files = copyRecursive(source: string, target: string, options: Options);
@marutypes
marutypes / PortalAbstraction.jsx
Last active October 26, 2017 15:29
A simple component to make using portals feel more componenty / declarative :)
import {Component} from 'react';
import {createPortal} from 'react-dom';
const isServer = (typeof window === 'undefined');
interface Props {
children: React.ReactNode,
}
class Portal extends React.Component<Props, never> {

Penning Yourself in (React)

Feel free to skip steps if you already have something installed.

Preparing your laptop

In your terminal:

  • installing hombrew (https://brew.sh/) /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Installing nodejs brew install node
  • Installing create-react-app npm install -g create-react-app

How 2 DI?

Right now our codebase has a bunch of Provider components at the top level which facilitate Higher-Order-Component based dep injection. Basically we're using #3. Is this good? Is this bad? Relay modern seems to be moving to a style more like #4, and there were some positive opinions about this it seems.

Personally, I really really don't like #4 because it is type-hostile (we need to type the props that are cloned in as optional or typescript will freak out when we don't pass them) and because it just seems the least explicit to me. That said, it seems there are some other strong opinions on this.

1. Just Imports and Singletons (Not do that)

//MyComponent.ts
import thingleton from '../../../wherever';
// CREATE REACT APP + CSS MODULES (replace existing style one)
{
test: /\.css$/,
loader: `style!css?importLoaders=1&modules&localIdentName=[name]__[local]___[hash:base64:5]!postcss`,
},
// SASS LOADER (put it under the css one!)
{
test: /\.scss$/,
include: paths.appSrc,