JS 生成随机字符串

Generate random characters Math.random().toString(36).replace(/[^a-z]+/g, '').slice(0, 5); Math.random(),生成随机数,例如:0.09751664076957856 .toString(36),转换成36进制后

Python 遍历指定目录下的文件

列出指定目录下的全部文件,或可以通过扩展名指定文件类型,也可以通过指定排除规则,忽略部分文件。 def list_files( dir: str, ext: list = None, recursive: bool = True, excludes: list = None ): """ Args: - dir, directory path.

Qt Pyside2 访问剪贴板

Qt/Pyside2 读取系统剪贴板内容 import sys from PySide2.QtWidgets import QApplication app = QApplication(sys.argv) clipboard = app.clipboard() print(clipboard.mimeData().formats()) print(clipboard.mimeData().data(clipboard.mimeData().formats()[0])) app.closeAllWindows() app=None mimeData() 就和 drag 时对 mimeData() 的操作一样了。 引用自 doc.qt.io: QClipboard supports the same data types that QDrag does, and uses similar mechanisms. For advanced clipboard usage read Drag and Drop .

Shell use clipboard to copy and paste

copy copy text file content to clipboard pbcopy < file.txt copy command stdout to clipboard ps aux | pbcopy copy text echo text | pbcopy paste paste from clipboard to file pbpaste > file.txt filter string pbpaste | grep "hello" > file2.txt echo text from clipboard echo | pbpaste Reference https://www.macobserver.com/tips/quick-tip/use-clipboard-in-terminal-without-mouse/

JS 自动滚动页面到底部

function getScrollTop() { var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0; if (document.body) { bodyScrollTop = document.body.scrollTop; } if (document.documentElement) { documentScrollTop = document.documentElement.scrollTop; } scrollTop = bodyScrollTop - documentScrollTop > 0 ? bodyScrollTop : documentScrollTop; return scrollTop; } function getScrollHeight() { var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0; if (document.body) { bodyScrollHeight = document.body.scrollHeight; } if (document.documentElement) { documentScrollHeight = document.documentElement.scrollHeight; } scrollHeight =

git 统计仓库中代码行数

列出每个文件行数,以及总行数 git ls-files | xargs wc -l 指定文件夹 git ls-files src lib | xargs wc -l 以上示例是指定仓库中 lib 文件夹 过滤文件夹或文件类型 git ls-files | grep -Ev 'examples|.txt' | xargs wc -l 以上示

Python 取列表共有元素(交集)

交集:对于给定的两个集合,返回一个包含两个集合中共有元素的新集合。 使用 Python 元组数据类型 set 来实现交集操作。 a = [1, 2, 3] b = [3, 4, 5] c = set(a).intersection(set(b)) print(list(c)) # [3]