Skip to content

Instantly share code, notes, and snippets.

Avatar
🔥
SLAYING BUGS

Wes Bos wesbos

🔥
SLAYING BUGS
View GitHub Profile
View prompt.ts
import dotenv from "dotenv";
import { readFile, writeFile } from 'fs/promises';
dotenv.config();
import { Configuration, OpenAIApi } from "openai";
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
export const openai = new OpenAIApi(configuration);
@wesbos
wesbos / settings.json5
Created December 21, 2022 16:30
VS Code Italic Comments
View settings.json5
{
"editor.tokenColorCustomizations": {
// just one
"comments": {
"fontStyle": "italic",
},
// multiple scopes
"textMateRules": [
{
"scope": [
@wesbos
wesbos / nuke-bot-tags.js
Created November 29, 2022 19:48
grease monkey script to remove bot tags
View nuke-bot-tags.js
// ==UserScript==
// @name Remove Bot Tags
// @version 1
// @grant none
// ==/UserScript==
function nukeEm() {
console.log('Nuke em!');
Array.from(document.querySelectorAll('a[href*="SaveTo"], a[href*="memdotai"]'))
.map(link => {
View non-empty-string.ts
// 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
View tik-tok-photoboot-app.html
<!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>
View fix-notion.js
function fixNotionPadding() {
Array.from(document.querySelectorAll(`[style*="padding-left: 96px"]`)).forEach(el => el.style.padding = 0);
requestAnimationFrame(fixNotionPadding);
}
fixNotionPadding();
View detect.ts
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;
@wesbos
wesbos / service-worker.js
Created March 24, 2022 18:26
Nuke a service worker from inside a service worker
View service-worker.js
// 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
View you-cant-spell-without.ts
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);
}
View tls.js
[
"",
"AC",
"AD",
"AE",
"AF",
"AG",
"AI",
"AL",
"AM",