Last active: 2 years ago
export const BtnItem = styled.div`
margin: 0.12rem 0;
width: 2.01rem;
height: 0.62rem;
background-size: 2.01rem 0.62rem;
padding: 0 0 0 0.63rem;
color: royalblue;
${() => {
if (theme.defaultTheme) return;
return css`
color: ${theme.mainColor};
`;
}}
}
Last active: 2 years ago
fn fibonacci(n: usize) -> Vec<usize> {
let mut f = (1, 1);
let mut fibo = vec![1, 1];
let calc = |_| {
f = (f.1, f.0 + f.1);
fibo.push(f.1);
};
if n > 2 {
(0..n - 2).for_each(calc);
}
fibo
}
Last active: 2 years ago
from redux source code. isPlainObject.ts
/**
* @param obj The object to inspect.
* @returns True if the argument appears to be a plain object.
*/
export default function isPlainObject(obj: any): boolean {
if (typeof obj !== 'object' || obj === null) return false
let proto = obj
while (Object.getPrototypeOf(proto) !== null) {
proto = Object.getPrototypeOf(proto)
}
return Object.getPrototypeOf(obj) === proto
}
Last active: 2 years ago
useMouseDragScrool.ts
import React, { useCallback, useEffect, useRef } from 'react';
import Scrollbars from 'react-custom-scrollbars-2';
const useMouseDragScrool = (ref?: React.RefObject<Scrollbars>) => {
// ScrollBars
const _scrollRef = useRef<Scrollbars>(null);
const scrollRef = ref ?? _scrollRef;
// ScrollBars 可滚动的 container
const scrollWrapper = useRef<Element>();
// 可滚动的最大距离
const maxScrollWidth = useRef(0);
useEffect(() => {
if (scrollRef.current?.container.firstElementChild) {
scrollWrapper.current = scrollRef.current?.container.firstElementChild;
}
if (
scrollRef.current?.getScrollWidth &&
scrollWrapper.current?.clientWidth != null
) {
Last active: 2 years ago
yarn add -D typescript-styled-plugin
{
"compilerOptions": {
"plugins": [
{
"name": "typescript-styled-plugin"
}
]
}
}
Last active: 2 years ago
https://steamcommunity.com/tradeoffer
const clickEvent = document.createEvent('MouseEvents');
clickEvent.initEvent('dblclick', true, true);
document.querySelectorAll('.inventory_page').forEach((item) => {
for (const i of item.children) {
for (const j of i.children) {
j.dispatchEvent(clickEvent);
}
}
});
Last active: 2 years ago
useCopyToClipboard.ts
import { useCallback, useState } from 'react';
type CopiedValue = string | null;
type CopyFn = (text: string) => Promise<void>; // Return success
/**
* 使用 clipboard API writeText 写入字符到剪贴板
*
* copy 方法为 memoized
* @returns
*/
function useCopyToClipboard() {
const [copiedText, setCopiedText] = useState<CopiedValue>(null);
const copy: CopyFn = useCallback(async (text) => {
const copyWithOldWay = () => {
const el = document.createElement('textarea');
el.value = text;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
Last active: 3 years ago
Compress gLTF model with gltf-pipeline
gltf-pipeline -i scene.gltf -o modelDraco.gltf -d
Last active: 3 years ago
Load gLTF model with draco compressed
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader';
import { GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader';
const manager = new THREE.LoadingManager();
const gltfLoader = new GLTFLoader(manager);
const dracoLoader = new DRACOLoader();
dracoLoader.setDecoderPath('./libs/draco/');
dracoLoader.setDecoderConfig({ type: 'wasm' });
gltfLoader.setDRACOLoader(dracoLoader);
gltfLoader.load('./models/just_a_hungry_cat/scene.gltf', handleLoad);