Skip to content

Instantly share code, notes, and snippets.

Avatar
🤖
<unk> <unk> <unk>

Zecong Hu huzecong

🤖
<unk> <unk> <unk>
View GitHub Profile
@huzecong
huzecong / io-link-for-github-profile-page.js
Created Apr 3, 2020
A Tampermonkey userscript to display .github.io links on user's profile page. https://greasyfork.org/en/scripts/399423-io-link-for-github-profiles
View io-link-for-github-profile-page.js
@huzecong
huzecong / load_multiple_json_objects.py
Created Apr 1, 2020
Load multiple JSON objects from a single string, in linear time.
View load_multiple_json_objects.py
# There are times when you're supposed to output a JSONL file, but forgot to put newlines between JSON objects.
# The `pickle` package can handle things like that, but `json` would complain that there are extra trailing characters
# and refuse to parse, although it's perfectly capable of doing so. What a stupid design.
# This snippet utilized lower-level APIs in `json` to handle such case.
import json
from typing import Any, List
import tqdm
@huzecong
huzecong / remove_pdf_text.py
Created Jan 29, 2020
A snippet to remove the watermark from a certain PDF book. You'll still need to manually locate the watermark element though.
View remove_pdf_text.py
import os
from PyPDF2 import PdfFileReader, PdfFileWriter
from PyPDF2.filters import FlateDecode
DIR = "path/to/pdf/file"
def main():
pdf = PdfFileReader(os.path.join(DIR, "pfpl.pdf"))
@huzecong
huzecong / guess_colloquium.py
Created Jan 29, 2020
A snippet to guess the shoutkey for LTI colloquiums
View guess_colloquium.py
import itertools
from typing import List, Optional
import requests
def get_url(url_base: str, xs: List[int]) -> str:
return url_base + "".join(chr(x + 97) for x in xs)
@huzecong
huzecong / options.py
Last active Sep 24, 2020
A super-enhanced version of namedtuple that supports multiple inheritance and arbitrary field orders.
View options.py
import collections
import typing
__all__ = [
"Options",
]
class OptionsMeta(typing.NamedTupleMeta):
def __new__(mcs, typename, bases, namespace):
You can’t perform that action at this time.