Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

swyx sw-yx

🎯
Focusing
Block or report user

Report or block sw-yx

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@sw-yx
sw-yx / NETLIFY_ENV_VARS.js
Last active Aug 24, 2019
BIG FAT LIST OF NETLIFY ENV VARS
View NETLIFY_ENV_VARS.js
process.env = {
/**
*
* AUTOMATICALLY SET BY NETLIFY. IMMUTABLE!
* docs: https://www.netlify.com/docs/continuous-deployment/#environment-variables
*
*/
NETLIFY: 'true',
// // URLs
@sw-yx
sw-yx / oclifconf2019.md
Last active May 31, 2019
oclifconf2019 notes
View oclifconf2019.md

some notes

  • decent representaiton here across paypal, twilio, apollo, stripe, intuit, adobe/cordova, and thats just the people ive met so far. and ofcourse salesforce, heroku, and netlify
  • jeff dickey (oclif creator) leaving heroku. not sure what hes doing next
  • salesforce cli has 16k total unique users, ~2k daily active. 90 community plugins
  • twilio is launching a big oclif initiative at Signal Conf in a few weeks
  • paypal working on something big too, a few devs here
  • salesforce/heroku have 10 people fulltime and 70ish domain expert contributors on CLI. a lot more community plugin contributors
@sw-yx
sw-yx / adaptive_intent.md
Created May 3, 2019
an adaptive, intent based CLI "state machine"
View adaptive_intent.md

an adaptive, intent based CLI "state machine"

one realization from working on Netlify's CLI is that the CLI framework we used, oclif, didn't provide a great user experience out of the box.

Emphasis on great: it does a lot of nice things, like offering flag and argument parsing, help documentation, and pluggability. That's good for the CLI developer. But what about the CLI user?

  • Idiomatic oclif code often checks for required preconditions, and if it doesn't exist, it prints a warning and then process.exit(1).
  • Decent code prints a helpful warning telling the user what they got wrong. It is informative.
  • Better code offers a prompt, creates a file, or something similar to solve the precondition before proceeding. (possibly recursively). It is intent-based.
  • Great code remembers past inputs to prompts and uses that to offer useful defaults. It is adaptive.
@sw-yx
sw-yx / createCtx-noNullCheck.tsx
Last active Aug 24, 2019
better createContext APIs with setters, and no default values, in Typescript
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
sw-yx / final submission.md
Last active Apr 16, 2019
Why React is Not Reactive - React Rally CFP
View final submission.md

This is the CFP for my React Rally talk, which was eventually accepted and given here: https://www.youtube.com/watch?v=nyFHR0dDZo0

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
sw-yx / Towards Active Sponsorship Strategy.md
Created Mar 26, 2019
Towards Active Sponsorship Strategy
View Towards Active Sponsorship Strategy.md

Watching our sponsorship play out this quarter, I thought I would pen down some thoughts as to how we can continue to evolve it:

Sponsorship goals and tradeoffs

Having a Sponsorship budget is a luxury as well as a limited resource. We all want to get a great ROI, which we know can exist even if attribution is difficult (need for multiple touch points, as well as long distance to conversion).

Additionally, we want to minimize workflow and response time (for example, having areas of clear "no's" allows support and marketing to better triage).

However, we also want to be responsive to unforeseen opportunities that may crop up. Unforeseen is perhaps a negative framing - the other way to look at it is "inbound". Inbound opportunities may be more authentic/genuine for a number of reasons, with ROI implications (good: event genuinely wouldnt happen without us, organizers go above and beyond in their reciprocation. bad: event may not be snapped up by other sponsors for a reason). This may involve keeping "dry

@sw-yx
sw-yx / Optimistic, Offline-first apps using serverless functions and GraphQL.md
Last active Apr 21, 2019
Optimistic, Offline-first apps using serverless functions and GraphQL
View Optimistic, Offline-first apps using serverless functions and GraphQL.md

Optimistic, Offline-first apps using serverless functions and GraphQL

Some thoughts on the challenges of the first 2 and possibly solving them with the latter 2.

Optimistic

In a world where API latency is unpredictable, the way to make user interactions seem instant is essentially by lying to the user. Most implementations of optimistic updates work like this:

  • duplicate what the result of the interaction would be in clientside code, while sending off the interaction to the server.
  • (optional) If this succeeds, the legitimate result may replace the clientside simulated result
@sw-yx
sw-yx / Write My Code For Me: Cheating at Developer Experience.md
Last active Jul 13, 2019
some thoughts on adding templating/scaffolding to CLIs and how it can be done well
View Write My Code For Me: Cheating at Developer Experience.md

Write My Code For Me: Cheating at Developer Experience

this is a draft of a blogpost that i'll be posting somewhere. Feedback welcome! also feel free to ping me on twitter

I've recently been working on some CLI that involves printing out a bunch of boilerplate template code for developer convenience. I found that there were a few interesting DX angles to this and figured I should write down the rough problem areas and the stances I chose. Most of us are familiar with CLIs like https://yeoman.io/, this task is variously called "scaffolding" or "templating" or some such similar term, with varying degrees of intelligence in the task. I'll refer to it as "templating" in this essay.

Part 1: Should You?

Caramel, not just Sugar

@sw-yx
sw-yx / formatTime.ts
Last active Jan 14, 2019
format time in typescript
View formatTime.ts
function formatTime(timeInSeconds: number) {
const hours = Math.floor(timeInSeconds / (60 * 60))
timeInSeconds -= hours * 60 * 60
const minutes = Math.floor(timeInSeconds / 60)
timeInSeconds -= minutes * 60
// left pad number with 0
const leftPad = (num: number) => `${num}`.padStart(2, '0')
const str =
(hours ? `${leftPad(hours)}:` : '') +
You can’t perform that action at this time.