Skip to content

Instantly share code, notes, and snippets.

View jacksteamdev's full-sized avatar

Jack Steam jacksteamdev

View GitHub Profile
@jacksteamdev
jacksteamdev / defer.ts
Last active June 17, 2020 21:54
Deferred Promise
/**
* Use this in testing to control when a promise resolves
*/
function defer<T>() {
let resolve: (value?: T) => void
let reject: (error: any) => void
const promise = new Promise<T>((res, rej) => {
resolve = res
reject = rej
})
@jacksteamdev
jacksteamdev / habit-tracker
Last active July 9, 2020 15:19
Text Blaze Snippets
Tracker Table for {time: MM-DD} -- {time: MM-DD; shift=+1D >SUN}{key:enter}{key:tab}{{table}}{key:enter}{key:tab}----------------{key:enter}{key:tab}Mon{key:enter}{key:tab}Tue{key:enter}{key:tab}Wed{key:enter}{key:tab}Thu{key:enter}{key:tab}Fri{key:enter}{key:tab}Sat{key:enter}{key:tab}Sun{key:enter}{key:enter}{key:enter}{key:enter}{key:enter}{key:enter}{key:enter}{key:enter}Plan PM{key:enter}{key:tab}{{[[TODO]]}}{key:enter}{key:tab}{{[[TODO]]}}{key:enter}{key:tab}{{[[TODO]]}}{key:enter}{key:tab}{{[[TODO]]}}{key:enter}{key:tab}{{[[TODO]]}}{key:enter}{key:tab}{{[[TODO]]}}{key:enter}{key:tab}{{[[TODO]]}}{key:enter}{key:enter}{key:enter}{key:enter}{key:enter}{key:enter}{key:enter}{key:enter}Spanish{key:enter}{key:tab}{{[[TODO]]}}{key:enter}{key:tab}{{[[TODO]]}}{key:enter}{key:tab}{{[[TODO]]}}{key:enter}{key:tab}{{[[TODO]]}}{key:enter}{key:tab}{{[[TODO]]}}{key:enter}{key:tab}{{[[TODO]]}}{key:enter}{key:tab}{{[[TODO]]}}{key:enter}{key:enter}{key:enter}{key:enter}{key:enter}{key:enter}{key:enter}{key:enter}Math{key
@jacksteamdev
jacksteamdev / please-include-a-repro.md
Last active October 20, 2020 19:09 — forked from Rich-Harris/please-include-a-repro.md
Please include a repro

Please include a repro

<some text explaining why we need a minimal reproduction repo: too much time, effort, etc...>

How to create a minimal reproduction

  1. Create a sample repo on GitHub
  2. Demonstrate the problem, and nothing but the problem. If the app where you're experiencing the issue happens to use Gulp, I don't care, unless the problem involves Gulp. Remove that stuff. Whittle it down to the bare minimum of code that reliably demonstrates the issue. Get rid of any dependencies that aren't directly related to the problem.
  3. Install all your dependencies to package.json. If I can't clone the repo and do npm install && npm run build (or similar – see point 4) to see the problem, because I need some globally installed CLI tool or whatever, then it's not really a minimal reproduction.
  4. Include instructions in the repo, along with a description of the expected and actual behaviour. Obviously the issue should include information about the bug as well, but it's really helpful if README.md
@jacksteamdev
jacksteamdev / ChangedFilesPlugin.js
Created November 12, 2020 22:14
Webpack Changed Files Logger Plugin
const fs = require("fs");
const filepath = "craco-changed-files.json";
/**
* This overwrites a log file of file changes that caused a rebuild.
*/
class ChangedFilesLogPlugin {
constructor() {
fs.writeFileSync(filepath, JSON.stringify([], null, 2), "utf8");
@jacksteamdev
jacksteamdev / .env
Created February 9, 2021 17:53
CRA CRX
# Eliminates inline script from index.html
INLINE_RUNTIME_CHUNK=false
@jacksteamdev
jacksteamdev / infer-example.ts
Last active August 3, 2021 15:40
TypeScript helpers
import { copyStream } from '../common/messages'
type Unarray<T> = T extends Array<infer R> ? R : T;
type Unobservable<T> = T extends Observable<infer R> ? R : T;
type Unpacked<T> = T extends Array<infer R> ? R : T extends Observable<infer R> ? R : never;
type CopyData = Unobservable<typeof copyStream>
type BackgroundEvent =
| { type: 'copy'; data: CopyData }
| { type: 'xstate.done.performCopy'; data: { tabId: string } }
@jacksteamdev
jacksteamdev / xpath-vs-css.md
Last active April 18, 2021 15:25
xpath vs css stackoverflow answer

I’m going to hold the unpopular on SO selenium tag opinion that XPath is preferable to CSS in the longer run.

This long post has two sections - first I'll put a back-of-the-napkin proof the performance difference between the two is 0.1-0.3 milliseconds (yes; that's 100 microseconds), and then I'll share my opinion why XPath is more powerful.


Performance difference

Let's first tackle "the elephant in the room" – that xpath is slower than css.

@jacksteamdev
jacksteamdev / SketchSystems.spec
Created April 18, 2021 14:54
My Awesome Sketch
My Awesome Sketch
First State
some event -> Second State
Second State
@jacksteamdev
jacksteamdev / Transcript.md
Created April 19, 2021 01:08
Lecture 1: How to Start a Startup

Lecture 1: How to Start a Startup by Y Combinator, genius.com This text is annotated! Click on the highlights to read what others are saying. If you'd like to add your own insights, comments, or questions to specific parts of the lecture, visit the lecture page on Genius, highlight the relevant text, and click the button that pops up. Your annotation will appear both here and on Genius.

Welcome to CS183B. I am Sam Altman, I'm the President of Y Combinator. Nine years ago, I was a Stanford student, and then I dropped out to start a company and then I've been an investor for the last few. So YC, we've been teaching people how to start startups for nine years. Most of it's pretty specific to the startups but thirty percent of it is pretty generally applicable. And so we think we can teach that thirty percent in this class. And even though that's only thirty percent of the way there, hopefully it will still be really helpful.

We've taught a lot of this class at YC and it's all been off the record. And this is

@jacksteamdev
jacksteamdev / assertEvent.ts
Last active May 10, 2021 15:34
xstate helpers
export function assertEventType<
TE extends EventObject,
TType extends TE['type']
>(event: TE, eventType: TType): asserts event is TE & { type: TType } {
if (event.type !== eventType) {
throw new Error(
`Invalid event: expected "${eventType}", got "${event.type}"`,
)
}
}