Skip to content

Instantly share code, notes, and snippets.

View GitaiQAQ's full-sized avatar
🏠
Working for home

Gitai GitaiQAQ

🏠
Working for home
View GitHub Profile
nvm use
npm install --location=global pnpm@${$(cat package.json | jq -r '.engines.pnpm // "latest"'):-latest}
npm install --location=global yarn@${$(cat package.json | jq -r '.engines.yarn // "latest"'):-latest}
npm install --location=global npm@${$(cat package.json | jq -r '.engines.npm // "latest"'):-latest}
// ==UserScript==
// @name urlbox-example
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://*/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=bing.com
// @grant none
// ==/UserScript==
export function createPendingValue<T, Ref = any, S = never>(ref: Ref, key: keyof Ref) {
let resolve!: (v: T) => void;
let reject!: (reason?: any) => void;
const p = new Promise<T>((_resolve, _reject) => {
resolve = value => {
ref[key] = value as Ref[keyof Ref];
_resolve(value);
};
@tailwind base;
@tailwind components;
@tailwind utilities;
#aside-controller:checked+aside {
transform: translateX(0);
}
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
// Version 2, December 2004
// Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
// Everyone is permitted to copy and distribute verbatim or modified
// copies of this license document, and changing it is allowed as long
// as the name is changed.
// DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
function payload<D, E>() {
const arr: { data?: D, error?: E } & ((_: any) => void)[] = [(data) => { arr.data = data }, (error) => { arr.error = error }];
return arr;
}
const useForceUpdate = () => Object.assign.apply(null, useReducer(({ current }) => ({ current: current + 1 }), { current: 0 }).reverse());
function useFetch<D, E, R = { data?: D, error?: E }>(fetcher, deps = []) {
const forceUpdate = useForceUpdate();
const ref = useRef<R>(payload());
@GitaiQAQ
GitaiQAQ / useForceUpdate.js
Created June 1, 2022 15:44
useForceUpdate
const useForceUpdate = () => Object.assign.apply(null, useReducer(({ current }) => ({ current: current + 1 }), { current: 0 }).reverse());
functioin Test() {
const forceUpdate = useForceUpdate();
const dataMap = useMemo(() => new WeakMap(), [forceUpdate.current]);
}
@GitaiQAQ
GitaiQAQ / InvertedPromise.js
Created June 1, 2022 15:34
InvertedPromise.js
function InvertedPromise() {
let _ = undefined;
return Object.assign(new Promise((resolve, reject) => { _ = { 0: resolve, 1: reject, resolve, reject } }), _);
}
function InvertedPromise() {
let _ = undefined;
return _ = new Promise((resolve, reject) =>
Promise.resolve()
.then(() => Object.assign(_, { resolve, reject })));
#!/usr/bin/env bash
# only-dev && only execute in dev env and throw an error in other
# only-dev || only execute in non-dev env and do nothing in other
if [[ $NODE_ENV =~ ^dev ]]
then
exit 0
fi
exit -1
import React, { Component, useCallback, useRef, useState } from 'react'
import { View, Text, Button } from '@tarojs/components'
import VirtualList from '@tarojs/components/virtual-list'

function buildData(offset = 0) {
  return Array(100)
    .fill(0)
    .map((_, i) => i + offset)
}