Skip to content

Instantly share code, notes, and snippets.

@julenwang
julenwang / copyDmhyAllMagnet.js
Last active May 20, 2022 05:12
copy dmhy all magnet urls
// ==UserScript==
// @name copyDmhyAllMagnet.js
// @version 0.1.1
// @description 2022/05/05
// @author Julen
// @match https://share.dmhy.org/topics/list?*
// @icon https://www.google.com/s2/favicons?sz=64&domain=dmhy.org
// @grant none
// ==/UserScript==
@julenwang
julenwang / deleteLeetcodeNodes.js
Last active December 10, 2021 08:26
删除 leetcode 题解页的额外元素,用于网页截图
// ==UserScript==
// @name deleteLeetcodeNodes.js
// @namespace manual
// @match https://leetcode-cn.com/*
// @version 0.3
// @author Julen
// @description 2021/12/10 下午3:30:44
// @grant GM_registerMenuCommand
// ==/UserScript==
@julenwang
julenwang / BarrierMouseSpeedFix_SurfacePro.ps1
Created November 15, 2021 05:21
BarrierMouseSpeedFix_SurfacePro.ps1
<#
.SYNOPSIS
Adjust the mouse speed when using Barrier (on Windows) to control another computer.
.DESCRIPTION
When using Barrier (https://github.com/debauchee/barrier) across two computers of different
resolutions/DPIs, the server's mouse speed may be too fast or too slow on the client computer:
https://github.com/debauchee/barrier/issues/741. This script monitors Barrier's log file and adjusts
the server's mouse speed when the mouse has moved onto the client.
Inspired in full by Aaron Jensen's (https://github.com/aaronjensen) script at
https://github.com/debauchee/barrier/issues/741#issuecomment-655317497.
@julenwang
julenwang / singleton.ts
Created November 7, 2021 09:23
singleton high order function
interface NewableFunc {
new (...args: any): any;
}
function singleton<T extends NewableFunc>(clazz: T): T {
let instance: T | undefined;
return new Proxy<T>(clazz, {
construct: (Target, argArray) => {
if (instance) {
return instance;
@julenwang
julenwang / useArbitraryDrag.ts
Last active October 22, 2021 09:37
useArbitraryDrag.ts
import { CSSProperties, MutableRefObject, RefCallback, useCallback, useMemo, useRef, useState } from 'react';
import { useDrag } from 'react-dnd';
import { transformPxToRemString } from '@/utils/doms';
const initOffset = { x: 0, y: 0 };
const useArbitraryDrag = (): {
ref: RefCallback<HTMLElement>;
style: CSSProperties;
} => {
@julenwang
julenwang / useDelayLoading
Last active October 22, 2021 09:37
useDelayLoading
import { useEffect, useRef, useState } from 'react';
const useDelayLoading = (isLoading: boolean, delay = 1500): boolean => {
const [loading, setLoading] = useState(false);
const timerRef = useRef<number>();
useEffect(() => {
const timer = timerRef.current;
if (isLoading) {
timerRef.current = setTimeout(() => {
@julenwang
julenwang / useRem
Last active October 22, 2021 09:37
useRem
import { useState } from 'react';
import { getRemNumber } from '@/utils/doms';
import { useEventListener } from 'ahooks/es';
import * as _ from 'lodash';
export function getRemNumber(): number {
const fontString = getComputedStyle(document.documentElement).getPropertyValue('font-size');
return Number(fontString.replace(/[^0-9.]/g, ''));
}
export function transformPxToRemString(length: number, precision = 3) {
import { Merge } from 'type-fest';
export type AsyncFunction = (...args: any[]) => Promise<any>;
/**
* 扩展对象联合类型的每一项
*/
export type ExpandObjectUnion<Union, Item extends Record<string, unknown>> = Union extends unknown
? Merge<Union, Item>
: never;
export type NonNullableAll<T> = {
@julenwang
julenwang / BarrierMouseSpeedFix.ps1
Created October 12, 2021 10:14 — forked from psignoret/BarrierMouseSpeedFix.ps1
Adjust the mouse speed when using Barrier (on Windows) to control another computer.
<#
.SYNOPSIS
Adjust the mouse speed when using Barrier (on Windows) to control another computer.
.DESCRIPTION
When using Barrier (https://github.com/debauchee/barrier) across two computers of different
resolutions/DPIs, the server's mouse speed may be too fast or too slow on the client computer:
https://github.com/debauchee/barrier/issues/741. This script monitors Barrier's log file and adjusts
the server's mouse speed when the mouse has moved onto the client.
function generateUUID(): string {
return new Array(4)
.fill(0)
.map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16))
.join("-");
}