Skip to content

Instantly share code, notes, and snippets.


swyx sw-yx

View GitHub Profile
sw-yx / final
Last active Mar 5, 2021
Why React is Not Reactive - React Rally CFP
View final

This is the CFP for my React Rally talk, which was eventually accepted and given here:

Final Submission: Why React is not Reactive

Functional-reactive libraries like RxJS make it easy to understand how data changes, giving us tools to declaratively handle events and manage state. But while our render methods react to state changes, React isn’t reactive. Instead, we write imperative event-handlers, and trip up on gotchas like async setState and race conditions. Why? In this talk we build a Reactive React to show the difference between the "push" and "pull" paradigms of data flow and understand why React chooses to manage Scheduling as a core Design Principle, enabling awesome features like async rendering and Suspense!

Theme: This talk is a deep dive into React's core design principle around scheduling. Instead of abstract discussion, we make it accessible and real by exploring an alternate universe in which React was an FRP library and actually run

sw-yx /
Last active Mar 5, 2021
Learn In Public - 7 opinions for your tech career

2019 update: this essay has been updated on my personal site, together with a followup on how to get started

2020 update: I'm now writing a book with updated versions of all these essays and 35 other chapters!!!!

1. Learn in public

If there's a golden rule, it's this one, so I put it first. All the other rules are more or less elaborations of this rule #1.

You already know that you will never be done learning. But most people "learn in private", and lurk. They consume content without creating any themselves. Again, that's fine, but we're here to talk about being in the top quintile. What you do here is to have a habit of creating learning exhaust. Write blogs and tutorials and cheatsheets. Speak at meetups and conferences. Ask and answer things on Stackoverflow or Reddit. (Avoid the walled gardens like Slack and Discourse, they're not public). Make Youtube videos

sw-yx / react-query.d.ts
Last active Mar 3, 2021
react query fixed working types - its not updated for v1 so i fixed locally
View react-query.d.ts
// Type definitions for react-query 0.3
// Project:
// Definitions by: Lukasz Fiszer <>
// Jace Hensley <>
// Matteo Frana <>
// Definitions:
import { ComponentType } from 'react';
// overloaded useQuery function with pagination
sw-yx / createCtx-noNullCheck.tsx
Last active Feb 24, 2021
better createContext APIs with setters, and no default values, in Typescript. this is documented in
View createCtx-noNullCheck.tsx
// create context with no upfront defaultValue
// without having to do undefined check all the time
function createCtx<A>() {
const ctx = React.createContext<A | undefined>(undefined)
function useCtx() {
const c = React.useContext(ctx)
if (!c) throw new Error("useCtx must be inside a Provider with a value")
return c
return [useCtx, ctx.Provider] as const
sw-yx / diversity in
Created Oct 6, 2020
diversity in tech resources and organizations. done as part of research for
View diversity in

US Centric (but often Worldwide)

Don't forget there are many state and city level organizations that can help you too.


  • US centric/Global:
    • Wonder Women Tech - We highlight, celebrate, and educate Women and the Underrepresented in Science, Technology, Engineering, the Arts, Math (STEAM) and Innovation. We nourish the global life cycle of the pipeline through equity, access, and opportunity.
    • FWD: For Women & Diversity Collective - We are a community dedicated to professional inclusion. We host summits & workshops featuring women, P.O.C., and under-represented groups for the experts that we are rather than the boxes that we check.
View clubhouse blogpost

Clubhouse is a great way to access celebrities but a terrible listening experience. They got all the growth factors right, but none of the retention and compounding factors.

Andrew Chen, Ryan Hoover, Michael Grinich and Sahil Lavingia think it could be a $100b company — and they have insider knowledge of metrics. I don't think Clubhouse is a zero - it has genuinely created a new category - it's just not very valuable. I'm taking the other side of that bet (but of course wish them well).


sw-yx /
Last active Feb 3, 2021
Gatsby bootstrap lifecycle

Sequence of Gatsby's bootstrap lifecycle with links to source code as of v2.0.0


  1. open and validate gatsby-config (get-config-file.js) 1.5 load themes (swyx added this note July 2019)
  2. load plugins (load-plugins/index.js) from the list given in gatsby-config.js
  3. onPreBootstrap: runs onPreBootstrap if it is implemented in any plugins, for example gatsby-plugin-typography. Receives handy [apiCallArgs](

4. Specialize in the New

You already know the value of a niche - you go up in market value the more specialized you are in anything. So what do you specialize in?

There are many schools of thought, including ones where you could be a generalist that doesn't specialize in anything. I find one rule to be simplest and most effective above all: Specialize in the New.

Didn't we just agree to avoid FOMO? Well yes, thats an important distinction - don't specialize in everything new. Specializing means you have to say no to a lot of things. Just pick something new that fascinates you, and hopefully many others as well. Since you're learning in public, you'll know when you hit on a real nerve. Budget in the idea that you'll fail a few times before you find Your Thing.

Then the other big objection: There are plenty of jobs/money/etc in (fill in the blank older technology) too! This is usually followed by some big numbers and anecdata. "My brother's cousin's roommate's friend took this COBOL job and now he's ear

sw-yx / Newton-1.29.vb
Last active Jan 20, 2021
Newton - my VBA utility library for doing matrix multiplication and other useful automations during my finance days
View Newton-1.29.vb
Attribute VB_Name = "Newton"
'Newton Utilities, written by swyx
'Project initiated Jan 1 2012
'V1 released Feb 5 2012
'V1.1 added and renamed functions, updated helpfiles Apr 8 2012
'V1.2 spline interp extraction from surface, n_RandomWalk. released Jun 15 2012
'V1.21 n_Corr, n_TangencyPortfolio, n_CovMat subsumed into n_Cov, fixed n_GetTimeSeries, n_AutoCorr, n_Lag, n_Pval, added PValues to n_Regress, n_Payback, n_ChartMakeScatter
'V1.22 n_Granger, pval for n_Corr, n_Divide, n_Curve, n_PriceIRS, upgraded n_BuildCurve
'V1.23 n_PriceFwd/Rate, n_AutoRegress/n_Remove_AutoRegress (needs work), augmented n_PriceOption for pricing FXO, digitals, and returning greeks
'V1.24 n_FXOVolCurve, n_FormatAsPercent linked to ctrl+shift+5, n_FormatInc/DecreaseDecimalPlace