TOC

几个小脚本

随便翻一下谷歌浏览器调试工具(F12)执行过的脚本,摘几个贴一下。

Gitee GVP

导出 GVP 项目列表,做个参考。

var jqEleProjects = $("#gvp-index-segment > div.ui.four.cards.all-projects > div > div.content.description-content");
var projects = {};
var languages = {};
var types = {};
jqEleProjects.each(function () {
    var name = $(this).find("h3 > a").text();
    var url = $(this).find("h3 > a").attr("href");
    var type = $(this).find("div > div > div:nth-child(1)").text();
    var language = $(this).find("div > div > div:nth-child(2)").text();
    projects[name] = { name: name, url: url, type: type, language: language };
    if (!languages.hasOwnProperty(language)) {
        languages[language] = [];
    }
    languages[language].push(name);
    if (!types.hasOwnProperty(type)) {
        types[type] = [];
    }
    types[type].push(name);
    // console.log(name + ' - ' + type + ' - ' + language + ' - ' + url);
});
console.log(projects);
console.log(languages);
console.log(types);

API 测试时先调登录接口

xhr = new XMLHttpRequest();
xhr.open("post", "http://localhost:9996/login", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("username=markjour&password=123456");

heidiSQL 找回数据库密码

get database password from heidisql settings file

有个配置文件,就在 heidisql 安装目录下,叫 settings.txt,自己找找。

function heidiDecode(hex) {
    var str = "";
    var shift = parseInt(hex.substr(-1));
    hex = hex.substr(0, hex.length - 1);
    for (var i = 0; i < hex.length; i += 2) str += String.fromCharCode(parseInt(hex.substr(i, 2), 16) - shift);
    return str;
}

Python 版本:

from __future__ import print_function

import re
import codecs

HEIDI_CONF = '/media/sf_D_DRIVE/Program Files/HeidiSQL/settings.txt'
HEIDI_CONF_SEP = re.compile(re.escape('<|||>'))


def heidi_pw_decode(code):
    shift = int(code[-1])
    code = code[:-1]
    password = ''.join(map(lambda x: chr(int(x, 16) - shift), re.findall(r'\w{2}', code)))
    return password


def main():
    with codecs.open(HEIDI_CONF, encoding="utf8") as fp:
        lines = [line.strip() for line in fp.readlines()
                 if line.startswith('Servers') and '\\Password<' in line]

    passwords = []
    for line in lines:
        parts = HEIDI_CONF_SEP.split(line)
        server_name = parts[0].split('\\')[1]
        password = heidi_pw_decode(parts[-1])
        passwords.append((server_name, password))

    if passwords:
        print(' All Database Passwords '.center(80, '-'))
        print()
        for server_name, password in passwords:
            print('Database: %s' % server_name)
            print('Password: %s' % password)
            print()
    else:
        print('[INFO] No password can be found!')


if __name__ == '__main__':
    main()

列出 Python 文档中的章节

我当时好像是为了比对 2 和 3 的文档章节差异,看看 3 多了些什么...

  • https://docs.python.org/2/library/
  • https://docs.python.org/3/library/
var chapters = {};
var arrL1 = $(".toctree-l1 > a");
var arrL2 = $(".toctree-l2 > a");
var content = "";
$(".toctree-l1").each(function () {
    var l1Title = $(this).find(arrL1).text();
    content += "- " + l1Title + "\n";
    chapters[l1Title] = [];
    $(this)
        .find(arrL2)
        .each(function () {
            var l2Title = $(this).html();
            l2Title = l2Title.replace(/<code class="docutils literal notranslate"><span class="pre">|<\/span><\/code>/g, "`");
            l2Title = l2Title.replace(/<strong class="program">|<\/strong>/g, "**");
            chapters[l1Title].push(l2Title);
            content += "  - " + l2Title + "\n";
        });
});
// console.log(JSON.stringify(chapters));
console.log(content);

自动删除网易邮箱的邮件

有些文件夹下的邮件实在太多,好几千封,两百大几十页,要是一个一个的全选、删除、等执行完成,那不累死,不是程序员该做的事。
写了个脚本,自动勾选删除。

PS:脚本没有找到,等找到了再补上。