Skip to content

Instantly share code, notes, and snippets.

View jacksteamdev's full-sized avatar

Jack Steam jacksteamdev

View GitHub Profile
@jacksteamdev
jacksteamdev / README.md
Created February 1, 2024 15:51
Chrome Extension Community Report

We're creating a Chrome Extension community report using data from Stack Overflow and Google Groups!

@jacksteamdev
jacksteamdev / popup.html
Created May 17, 2022 13:04
Firebase login example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Firebase Persistent Auth Example</title>
</head>
<body>
<h1 id="authState">Checking auth state...</h1>
@jacksteamdev
jacksteamdev / vite-plugin-react.ts
Created November 2, 2021 16:23
vite-plugin-crx-react
import react from '@vitejs/plugin-react'
import type { RPCEPlugin } from 'rollup-plugin-chrome-extension'
import type {
HmrOptions,
PluginOption,
ViteDevServer,
} from 'vite'
export default function createPlugins(
...args: Parameters<typeof react>
@jacksteamdev
jacksteamdev / usage.js
Last active November 4, 2021 14:12
XState Debug Helper
const service = interpret(someMachine);
debugHelper(service, (state, ids, actors) => {
// debug here, this will run on all actors
console.log(state, ids);
});
@jacksteamdev
jacksteamdev / manifest.json
Last active September 1, 2021 15:14
declarativeNetRequest example
{
"background": {
"service_worker": "service_worker.ts"
},
"content_scripts": [
{
"js": ["content.ts"],
"matches": ["https://www.google.com/*"]
}
],
@jacksteamdev
jacksteamdev / .eslintrc.cjs
Last active July 14, 2021 19:15
Sveltekit config files
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
plugins: ['svelte3', '@typescript-eslint'],
ignorePatterns: ['*.cjs'],
overrides: [
type WithTabWithId<Type> = Required<
{
[Property in keyof Type]: Type[Property] extends { id?: number }
? Type[Property] & { id: number }
: Type[Property]
}
>
const isWithTabWithId = <T>(args: T): args is WithTabWithId<T> => {
if (!Array.isArray(args)) return false
const tab = args.find(
@jacksteamdev
jacksteamdev / machine.js
Last active May 20, 2021 17:01
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@jacksteamdev
jacksteamdev / question-answers.md
Created May 13, 2021 15:33
What is an invariant?

Answer 1

An invariant is more "conceptual" than a variable. In general, it's a property of the program state that is always true. A function or method that ensures that the invariant holds is said to maintain the invariant.

For instance, a binary search tree might have the invariant that for every node, the key of the node's left child is less than the node's own key. A correctly written insertion function for this tree will maintain that invariant.

As you can tell, that's not the sort of thing you can store in a variable: it's more a statement about the program. By figuring out what sort of invariants your program should maintain, then reviewing your code to make sure that it actually maintains those invariants, you can avoid logical errors in your code.

Answer 2

import { writeText } from "./writeText";
import { notify } from "@extend-chrome/notify";
export const notifyCopy = (txt) => {
const btnTitle = "copy again";
return notify.create({
message: `"${txt}" was copied to the clipboard.`,
buttons: [{ title: btnTitle, onClick: () => writeText(txt) }],
});
};