Skip to content

Instantly share code, notes, and snippets.

View Gk0Wk's full-sized avatar
💻
Focusing

Ke Wang Gk0Wk

💻
Focusing
View GitHub Profile
@Gk0Wk
Gk0Wk / github_host.py
Last active July 23, 2021 09:30
(墙内用)获取GitHub的最快HostIP
# 使用说明
# 请先安装`BeautifulSoup`和`requests`,并运行py脚本,将得到的输出保存至hosts文件。
import requests
from bs4 import BeautifulSoup
github_domain_list = [
'github.com',
'github.io',
'githubstatus.com',
@Gk0Wk
Gk0Wk / query_minecraft_server.py
Created July 23, 2021 09:30
查询Minecraft服务器状态
import requests
def query(url:str):
result = requests.get(f'https://api.mcsrvstat.us/2/{url}').json()
import json
if result['debug']['ping'] == False:
return None
else:
return {
'online_players': [player for player in result['players']['uuid'].keys()],
@Gk0Wk
Gk0Wk / find_by_baidu.py
Created July 23, 2021 09:32
百度搜索获取第一页的结果与链接
import requests
from bs4 import BeautifulSoup
def find_page(key_word, page=1):
ret = requests.get(url='https://www.baidu.com/s', params={'wd': key_word, 'pn': page}, headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36'})
soup = BeautifulSoup(ret.content.decode('utf-8'), 'lxml')
return {ele.a.get_text().strip(): ele.a['href'] for ele in soup.select('#content_left>div')}
print(find_page('GitHub'))
@Gk0Wk
Gk0Wk / clean_dsstore.sh
Created July 23, 2021 15:37
一键清理目录下所有.DS_Store
find . -name '.DS_Store' -type f -exec rm -v {} \;
@Gk0Wk
Gk0Wk / make_shuffle.py
Created July 23, 2021 15:38
很平均的打乱,每一步都符合条件概率
def shuffle(lst):
for i in range(len(lst))[::-1]:
rand = random.randint(0, i)
tmp = lst[rand]
lst[rand] = lst[i]
lst[i] = tmp
@Gk0Wk
Gk0Wk / umd_module_template(TiddlyWiki).js
Created August 26, 2021 17:38
UMD Module Template for JS
/* UMD 模块 https://blog.csdn.net/Real_Bird/article/details/54869066 不得不说没有ES6的export是真的麻烦 */
/* ()包住的是表达式,js会主动运行以求得值,所以其实不要一定是括号写法,也可以是 !f1(f2) 等等,目的是自动执行这段代码 */
(function(root, factory) {
/* 这段主要是用不同的方式去获取以一些依赖,如果没有依赖,其实可以不要这一段 */
if (typeof exports === "object" && typeof module === "object") // CommonJS规范(如NodeJS)
/* 依赖名称,相对路径../../lib/codemirror(.js)? (假设本文件是$:/plugins/tiddlywiki/codemirror/a/b/c.js) 和 绝对路径(如下)都可以 */
module.exports = factory(require("$:/plugins/tiddlywiki/codemirror/lib/codemirror.js"));
else if (typeof define === "function" && define.amd) // AMD规范(如require.js)
/* 同上,不过AMD的传参比较特殊,是把参数数组作为第一个参数,函数作为第二参数 */
define(["$:/plugins/tiddlywiki/codemirror/lib/codemirror.js"], factory);
(function(root, factory) {
if (typeof exports === "object" && typeof module === "object")
module.exports = factory();
else if (typeof define === "function" && define.amd)
define([], factory);
else if (typeof define === "function" && define.cmd)
define(function(require, exports, module) {
module.exports = factory();
});
else root.MyFileIO = factory();
@Gk0Wk
Gk0Wk / HorizontalStoryView.tid
Last active September 1, 2021 12:42
横版StoryView
tags: $:/tags/Stylesheet
title: 横版StoryView.tid
type: text/css
/* StoryRiver & Sidebar */
:root {
--story-river-top: 42px;
--story-river-bottom: 28px;
--max-tiddler-width: 800px;
}
@Gk0Wk
Gk0Wk / $__core_modules_utils_fakedom.js
Created September 8, 2021 02:58
FakeDocument + Linkedom
/*\
title: $:/core/modules/utils/fakedom.js
type: application/javascript
module-type: global
A barebones implementation of DOM interfaces needed by the rendering mechanism.
\*/
(function() {
@Gk0Wk
Gk0Wk / benchmark_for_traversing_on_js.md
Last active October 9, 2021 08:46
Benchmark for Traversing on JavaScript

Benchmark test part

My test environment:

  • Apple MacBook Pro 2017 (15-inch)
  • macOS Big Sur (v11.6 (20G165)), Darwin Kernel Version 20.6.0
  • CPU: 3.1 GHz Quad-Core Intel Core i7-7920HQ
  • Memory: LPDDR3 2133 MHz 8G x 2

I have tested it in four browsers: