Skip to content

Instantly share code, notes, and snippets.

View shanehh's full-sized avatar
🏠

SH shanehh

🏠
View GitHub Profile
@shanehh
shanehh / helium.py
Last active November 12, 2021 08:46
ChromeDriverManager + helium + no first run
import helium as H
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
def main():
opts = webdriver.ChromeOptions()
opts.add_argument("--no-first-run")
opts.add_argument("--no-service-autorun")
opts.add_argument("--no-default-browser-check")
@shanehh
shanehh / foo.py
Created September 7, 2021 06:18
make driver as a global variable, while under with
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
D = None
def google(keyword):
D.get(f"https://www.google.com.hk/search?q={keyword}")
In [17]: from __future__ import braces
File "<ipython-input-17-6d5c5b2f0daf>", line 1
from __future__ import braces
^
SyntaxError: not a chance
@shanehh
shanehh / weeknum.py
Created July 24, 2021 11:43
python datetime package 有提供符合 iso 8601 标准的 date.isoweekday. 此 snippet 的代码根据 date 算出 weeknum,像是 excel 里 WEEEKNUM 的默认行为:即不论如何,1/1 日是第一周,sunday 作为一周的第一天
import datetime as dt
def weeknum(date):
# 如果新年的第一天就是星期天的话
# 直接通过天数的差异算 weeknum
# 规则是:
# 1. 每满 7 天,周数加 1
# 2. 如果有余数,或余数就为 0(本身是 sunady 的情况)也加 1
# 最终数学公式就是:floor division 7, plus 1
@shanehh
shanehh / example.py
Created April 19, 2021 03:29
set IPython.embed as default breakpoint
import pandas as pd
import os
os.environ["PYTHONBREAKPOINT"] = "IPython.embed"
pd.read_excel("./accounts.xlsx")
breakpoint()
@shanehh
shanehh / create_any_MB_file.py
Created March 22, 2021 12:28
Sometimes you need to create a file of a specified size...
def create_any_MB_file(filepath, n):
with open(filepath, 'wb+') as f:
for _ in range(2**20 * n):
f.write(bytes(1))
@shanehh
shanehh / JustCopyIt.js
Created March 20, 2021 04:17
Bro, don't pollute my clipboard!
// ==UserScript==
// @name c
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.zhihu.com/question/*
// @match https://www.douban.com/note/*
// @grant none
// @run-at document-end
@shanehh
shanehh / HideWikiRefer.js
Created March 20, 2021 04:09
hide wiki referer number to make copy easier
// ==UserScript==
// @name HideWikiRefer
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author Huu
// @match https://*.wikipedia.org/wiki/*
// @match https://*.wikipedia.org/zh*/*
// @grant none
// @run-at document-end
@shanehh
shanehh / HideFilesSection.js
Created March 20, 2021 04:08
Auto click hide button at github repo page
// ==UserScript==
// @name HideFilesSection
// @namespace http://tampermonkey.net/
// @version 0.3
// @description I just need to see readme!!!
// @author lane
// @match https://github.com/*
// @exclude https://github.com/*/*/tree/*
// @grant none
// ==/UserScript==
@shanehh
shanehh / b站自动宽屏.js
Created March 20, 2021 04:06
b站自动宽屏
// ==UserScript==
// @name b站自动宽屏
// @author Huu Lane
// @description auto enable theater mode in bilibili.
// @version 3.0.0
// @include *://www.bilibili.com/video/*
// @namespace nobody_space
// ==/UserScript==
;(async function () {