Skip to content

Instantly share code, notes, and snippets.

View crutchcorn's full-sized avatar
📒
Writing like whoa

Corbin Crutchley crutchcorn

📒
Writing like whoa
View GitHub Profile
<template>
<div>
<div
v-for="field of fields"
:key="field.id"
>
<input
v-if="field.value === 'input'"
:value="field.value"
:aria-label="field.label"
<script>
// Base.js
class OurBaseComponent extends HTMLElement {
connectedCallback() {
this.doRender();
}
createState(obj) {
return Object.keys(obj).reduce((prev, key) => {
// This introduces bugs
@crutchcorn
crutchcorn / proxy-assign-mem-share.js
Last active October 19, 2021 12:38
Demonstration of how Object.assign, object mutation, and proxy binding play together in JS
const a = {
a: 100
}
const c = {
c: 300
}
function get_c_proxy(mainObj) {
return new Proxy(c, {
test("Should fail", async (t) => {
const { cleanup, getByText, fireEvent } = await render([""], {
cwd: resolve(__dirname, "../example"),
});
let outputStr;
outputStr = await waitFor(() => getByText("Please choose a generator"));
t.regex(outputStr, /Please choose a generator/);
cleanup();
// This basic premise is being used here:
// https://github.com/plopjs/plop/pull/287/files#diff-dc20b7684034e757bccdcb13b82e52fa46e618997d3fcc3e9fddd88bde362607R29-R73
let dataWaitPromises = [];
function waitForData() {
const promise = new Promise((resolve) => (localDataResolve = resolve));
dataWaitPromises.push({ promise, resolve: localDataResolve });
}
from math import inf
def find_closest_x_y(val, arr):
ret = {
"val": None,
"diffX": inf,
"diffY": inf
}
(val_x, val_y) = val
// Setup
const setLogout = () => {
const router = useRouter();
return () => {
// Do logout action here, including `router.push`
return 0;
}
}
Usage in `setup()`
// Source: https://gist.github.com/avneesh0612/d4221f520688c7c4ff45153441011b4c
import { useEffect, useState } from 'react';
function useDarkMode() {
const [theme, setTheme] = useState('dark');
const colorTheme = theme === 'dark' ? 'light' : 'dark';
useEffect(() => {
setTheme(localStorage.getItem('theme') || 'dark');
}, [])
const t = readline();
keyCodeMap = {}
addRangeToKeyCodeMap = (start, len) => {
for (i = 0; i < len; i++) {
keyCodeMap[start + i] = start + len - 1 - i
}
}
addLatinToKeyCodeMap = start => addRangeToKeyCodeMap(start, 26)
interface W {
test?: 0;
he: 0;
}
type OnlyOptional<T> = {
[key in keyof T as Extract<T[key], undefined> extends never ? never : key]: T[key];
}