Skip to content

Instantly share code, notes, and snippets.

View dragon-fish's full-sized avatar
🐟
Petting fish

机智的小鱼君 dragon-fish

🐟
Petting fish
View GitHub Profile
/**
* @param {string} src
* @param {Record<string, string>?} attrs
* @returns {Promise<HTMLScriptElement>}
*/
function loadScript(src, attrs = {}) {
return new Promise((res, rej) => {
const s = Object.assign(document.createElement('script'), { src })
Object.entries(attrs).forEach(([k, v]) => k && v !== void 0 && s.setAttribute(k, v))
s.onload = () => res(s)
#!/bin/bash
set -e
# =============================
# 参数与配置
# =============================
MONGOSH_FALLBACK_VERSION="2.5.1"
MONGOTOOLS_FALLBACK_VERSION="100.12.1"
@dragon-fish
dragon-fish / README.md
Last active June 30, 2025 07:19
GitHub Copilot AI (Python ver)
@dragon-fish
dragon-fish / BaseDecorator.php
Created June 13, 2025 04:13
PHP class decorator
<?php
declare(strict_types=1);
/**
* @template T of object
* @mixin T
*/
class BaseDecorator {
/** @var T */
@dragon-fish
dragon-fish / check_mw_autoload_files.py
Created June 11, 2025 17:43
Check MediaWiki autoload.php class files
#!/usr/bin/env python3
"""
Check MediaWiki autoload.php class files
此脚本读取 autoload.php 中定义的类文件,并检查它们是否存在以及大小写是否正确
MediaWiki 的发行版压缩包里有可能会出现文件名不对或者文件缺失的问题,头疼
"""
import os
import re
@dragon-fish
dragon-fish / fix_git_case_sensitive.py
Last active June 11, 2025 17:48
Fix Git Case-Sensitive File Names
#!/usr/bin/env python3
"""
Fix Git Case-Sensitive File Names
这个脚本用于修复 Git 仓库中因大小写不敏感导致的文件名冲突问题。
它会扫描所有已跟踪的文件,查找大小写冲突的文件名,并将其重命名为临时名称,
然后再重命名为最终名称,分两次提交。
用法:
@dragon-fish
dragon-fish / clickToSaveCanvas.js
Last active February 21, 2024 11:49
clickToSaveCanvas
;(() => {
if (window.clickToSaveCanvas) {
return window.clickToSaveCanvas()
}
/**
* @param {HTMLCanvasElement} canvas
*/
async function canvasToBlob(canvas) {
return new Promise((resolve) => {
@dragon-fish
dragon-fish / IpadCursor.ts
Last active April 13, 2023 06:52
An iPadOS cursor simulation for the browser
/**
* @author dragon-fish <dragon-fish@qq.com>
* @lisence MIT
* @refered https://github.com/hongkiulam/ipad-cursor-js by @hongkiulam
*/
const TEXT_ELEMENT_TAGS = ['P', 'SPAN', 'H1', 'H2', 'H3', 'H4', 'TEXTAREA']
export class IpadCursor {
public cursor = document.createElement('div')
@dragon-fish
dragon-fish / animatedNumber.ts
Created March 20, 2023 17:58
Animated number
function animatedNumber({
from = 0,
to = 0,
duration = 0,
onUpdate,
onFinish,
}) {
const startTime = performance.now()
;(function tick() {
const current = performance.now()
@dragon-fish
dragon-fish / loadScriptAsync.ts
Created March 13, 2023 15:12
loadScriptAsync.ts
function loadScriptAsync(src = '', { isModule = false, noCache = false }) {
return new Promise((resolve, reject) => {
const script = document.createElement('script')
script.async = true
if (noCache) {
src += `${src.includes('?') ? '&' : '?'}_=${Date.now()}`
}
script.src = src
isModule && (script.type = 'module')
script.addEventListener('load', resolve)