Skip to content

Instantly share code, notes, and snippets.

@ImN1
ImN1 / xpath2dict.py
Created March 4, 2022 06:42
python xpath string/text convert to nested dict
import json
def xpath2Dict(xpaths, nested:bool=True, sep:str='/')->Dict:
'''
xpaths: String | Iterable,前者按 splitlines 拆分为后者\n
可以包含或不包含枝节点,例如:\n
topnode/node\n
topnode/node/leaf\n
两条同时存在,或者仅有第二条,都能构建树状 dict。\n
分隔符在开头或结尾都会舍弃,相应的首节点、末节点按照处理后的 xpath 计算\n
#!/usr/bin/env python3
# -*-coding:utf-8 -*-
'''
A picture slideshow viewer widget
'''
import os
import natsort
@ImN1
ImN1 / grouped_similar_filenames.py
Created June 17, 2024 12:02
grouped similar filenames
def groupedSimilarFilenames(filenames):
'''
将相似文件名分组\n
输出类似格式\n
filenames preffix suffix size \n
0 cover.jpg NaN NaN 0 \n
1 top.png NaN NaN 0 \n
2 9.jpg NaN .jpg 0 \n
3 015a.jpg 0 a.jpg 1 \n
@ImN1
ImN1 / url_tagger.user.js
Created August 21, 2024 08:24
URL Tagger
// ==UserScript==
// @name URL Tagger
// @namespace http://tampermonkey.net/
// @version 1.5
// @description Tag URLs based on predefined patterns and data
// @author Your Name
// @match *://*/*
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @connect 192.168.x.x