Skip to content

Instantly share code, notes, and snippets.

View Vopaaz's full-sized avatar

Vopaaz Vopaaz

View GitHub Profile
fn = () => {
l = "0123456789qwertyuiopasdfghjklzxcvbnm"
candidates = []
for (const c1 of l) {
for(const c2 of l){
candidates.push(c1 + c2)
}
}
for (const suffix of candidates){
@Vopaaz
Vopaaz / Tsinghua-GPA-calc.js
Last active October 12, 2020 10:20
Calculate Tsinghua University GPA at the "All Scores", i.e. "本科生已修课程成绩查询" page
var reverse = (arr)=>{ // Array.prototype.reverse is overridden in a bloody way in the webpage
const res = []
for (let index = arr.length-1; index >= 0; index--) {
const element = arr[index];
res.push(element)
}
return res
}
(() => {
@Vopaaz
Vopaaz / git-prune.sh
Created June 28, 2020 10:16
Delete all local branches except for master
git branch | grep -v master | xargs git branch -d
import requests
from urllib.parse import quote
content = quote(r'''
\documentclass{article}
\title{Title}
\author{Author}
\date{\today}
@Vopaaz
Vopaaz / Scala-dynamic-typechecking.scala
Created December 19, 2019 19:12
Dynamically check the type of an object in Scala
import scala.reflect._
class Foo{
def expect[T: ClassTag](that: Any) = {
if (classTag[T].runtimeClass.isInstance(that)) {
doSomething
}
}
}
@Vopaaz
Vopaaz / Pandoc-md2pdf.sh
Last active December 19, 2019 19:10
Using pandoc to convert markdown file to pdf file.
pandoc -o OUTFILE.pdf --pdf-engine=xelatex -V mainfont="Microsoft YaHei" INFILE.md
@Vopaaz
Vopaaz / Chrome-header-for-Python-requests.py
Last active November 7, 2023 09:50
Converting the directly copied header from Chrome to the header dict that can be used in requests package.
def parse_header(raw_header: str):
header = dict()
for line in raw_header.split("\n"):
if line.startswith(":"):
a, b = line[1:].split(":", 1)
a = f":{a}"
else:
a, b = line.split(":",1)
@Vopaaz
Vopaaz / Python-json-dump.py
Last active December 19, 2019 19:10
Prettified json dump with proper indent and word wrap.
with open(file, "w", encoding="utf-8") as f:
json.dump(js_obj, f, indent=4, separators=(',', ': '))