Skip to content

Instantly share code, notes, and snippets.

View swyxio's full-sized avatar
🎯
Focusing

swyx.io swyxio

🎯
Focusing
View GitHub Profile
@swyxio
swyxio / types for estree with JSX.ts
Last active August 7, 2020 01:56
types for estree with JSX - the default estree types (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/estree/index.d.ts) dont come with JSX definitions so i made a short start on them. pls comment if you have more to add
interface Location {
start: number;
end: number;
};
interface JSXOpeningElement extends Location {
type: 'JSXOpeningElement',
attributes: JSXAttribute[],
name: JSXIdentifier,
selfClosing: boolean
@swyxio
swyxio / mobilenav.svelte
Created June 30, 2020 21:13
my mobile responsive nav
<script>
import { clickOutside } from "./actions.js";
let activeNav = "Home";
let isMobile;
let isMobileAndNavActive = false;
// $: console.log({ isMobile, isMobileAndNavActive });
function handleClickOutside() {
if (isMobile && isMobileAndNavActive) {
isMobileAndNavActive = !isMobileAndNavActive;
@swyxio
swyxio / stringify.ts
Created June 6, 2020 00:55
JSON stringify replacer (no circular deps) pretty printer
import parse5 from 'parse5'
var src = `
{#if name}
<script>
console.log('not top level')
</script>
{/if}
<ul>
{#each cats as cat}
@swyxio
swyxio / amplify docs requests.md
Last active June 5, 2020 12:30
amplify docs requests
@swyxio
swyxio / readme.md
Last active May 11, 2022 07:58
notes on how to video tutorial like a pro - https://www.youtube.com/watch?v=9lPjY-JGZDY

Notes for gregg pollack's https://www.youtube.com/watch?v=9lPjY-JGZDY

Tools: AUDIO > Video. Use a good mic. Film yourself w/ natural light & good backdrop when explaining ideas. Use Screenflow, high res monitor (for zooming). Hire a film editor. Keynote/powerpoint. Use Animations! Get everything captioned!

Instructional Design:

  • Describe the problem first, dont just teach syntax.
  • Give Learning Objectives.
  • Show them what you're going to build, what they need to know
  • teach with visuals where needed
  • Show more than one example
@swyxio
swyxio / readme.md
Last active January 16, 2022 10:36
svelte society day talks and resources -
// // with thanks
// https://dev.to/emreloper/react-router-v6-in-two-minutes-2i96
// https://github.com/ReactTraining/react-router/blob/dev/docs/installation/getting-started.md
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/9d29adedf662de685356f711951ef8b9e8342865/types/react-router/index.d.ts#L1
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/9d29adedf662de685356f711951ef8b9e8342865/types/react-router-dom/index.d.ts#L1
declare module "react-router-dom" {
import * as React from 'react';
/**
@swyxio
swyxio / Tailwindcssunreset.scss
Last active February 14, 2024 01:19
Tailwind CSS Un-Reset - un-reset Tailwind's Preflight CSS Reset so that autogenerated HTML looks consistent with the rest of your Tailwind site. - https://www.swyx.io/writing/tailwind-unreset
.unreset {
a {
@apply text-blue-700 underline;
}
p {
@apply my-4;
}
blockquote,
figure {
@swyxio
swyxio / chatscroller.jsx
Last active November 15, 2020 21:55
Handy Scroll window manager component for building a Slack-like Chat experience - when you want your chat window to autoscroll down when new messages appear, BUT not while you're scrolling up. Also useful for feedlike or log display components. from ryan florence workshop chat example (course at https://courses.reacttraining.com/courses/517181/…
function ChatScroller(props) {
const ref = useRef()
const shouldScrollRef = useRef(true)
useEffect(()=> {
if (shouldScrollRef.current) {
const node = ref.current
node.scrollTop = node.scrollheight
}
})
const handleScroll = () => {
@swyxio
swyxio / walk.js
Last active March 20, 2020 14:39
recursive crawl to get a list of filepaths
const fs = require('fs');
const path = require('path');
const { promisify } = require('util');
const readDir = promisify(fs.readdir);
// https://gist.github.com/kethinov/6658166
var walk = async function(dir, filelist) {
var files = await readDir(dir);
filelist = filelist || [];
await Promise.all(