This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Here we check if our custom type "Stringy" extends a narrow type of '' | |
// If it does, the type is never | |
// If it doesnt, the type is "Strinfy", which is just a string type | |
function getItem<Stringy extends string>( | |
id: Stringy extends '' ? never : Stringy | |
) { | |
// code here | |
} | |
// works: | |
getItem('abc123'); // No error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>🔥 Make a photo booth app in about 15 lines of JavaScript</title> | |
<link rel="icon" href="https://fav.farm/🎥" /> | |
</head> | |
<body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fixNotionPadding() { | |
Array.from(document.querySelectorAll(`[style*="padding-left: 96px"]`)).forEach(el => el.style.padding = 0); | |
requestAnimationFrame(fixNotionPadding); | |
} | |
fixNotionPadding(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { codes } from './database'; | |
const app = document.querySelector('.app') as HTMLDivElement; | |
const videoEl = app.querySelector('video'); | |
const canvasEl = app.querySelector('canvas'); | |
const labelsEl = app.querySelector('.labels') as HTMLDivElement; | |
const ctx = canvasEl.getContext('2d'); | |
interface Window { | |
BarcodeDetector: any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// put this in a file where your service worker used to live, like yourdomain.com/service-worker.js. You can find out this path in the SW dev tools of your browser | |
self.addEventListener('install', (e) => { | |
console.log('[Service Worker] Installing Service Worker ...', e); | |
self.skipWaiting(); | |
}); | |
self.addEventListener('activate', (e) => { | |
console.log('[ServiceWorker] Activate'); | |
self.registration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Without { | |
without(withoutWord: string): boolean; | |
} | |
// 1. Easiest / the way I'd do it | |
function youCantSpell(word: string): Without { | |
return { | |
without(withoutWord: string) { | |
return word.includes(withoutWord); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
"", | |
"AC", | |
"AD", | |
"AE", | |
"AF", | |
"AG", | |
"AI", | |
"AL", | |
"AM", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function update(cache, payload) { | |
cache.evict(cache.identify(payload.data.deleteCartItem)); | |
} | |
const [removeFromCart, { loading }] = useMutation(REMOVE_FROM_CART_MUTATION, { | |
variables: { id }, | |
update, | |
// When the optimistic response comes back, it seems to re-fetch every single query on the page, leaving `data` from queries undefined (and loading and error undefined as well), causing the layout to break. | |
// // The error itself comes from next.js, and it does seem that the item is evicted from the cache before that happens... | |
// optimisticResponse: { |
This file has been truncated, but you can view the full file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[{"id":1,"start":2.46,"end":21.12,"text":"Hello, everybody, and welcome to syntax. This is a new podcast that Scott and I are launching. And we already have three episodes recorded. And we'll be launching them shortly. For now we just wanted to let you know that we're going to be launching this podcast. And to sort of get you subscribe to the feed so that when they're ready to drop, you're ready to get them.","speaker":"Wes Bos","initials":"WB","timestamp":{"hh":"00","mm":"00","ss":"02"}},{"id":2,"start":21.3,"end":27.66,"text":" And this is a web development podcast filled with tasty tips and treats for web developers. ","speaker":"Scott Tolinski","initials":"ST","timestamp":{"hh":"00","mm":"00","ss":"21"}},{"id":3,"start":27.96,"end":39.42,"text":"Oh, oh, yeah. So a little bit about ourselves. My name is Wes Bos. I am a full stack developer from Canada. And I essentially create training courses that help web developers get better at their job. ","speaker":"Wes Bos","initials":"WB","timestamp":{"hh":"00"," |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// deno run --allow-net --allow-write download-shows.ts | |
import { download } from "https://deno.land/x/download/mod.ts"; | |
const showList = 'https://syntax.fm/api/shows'; | |
async function getShowList(): Promise<Show[]> { | |
const list = await (await fetch(showList)).json(); | |
return list; | |
} |