Skip to content

Instantly share code, notes, and snippets.

View huzecong's full-sized avatar
🤖
<unk> <unk> <unk>

Zecong Hu huzecong

🤖
<unk> <unk> <unk>
View GitHub Profile
@huzecong
huzecong / fix-sony-heif.sh
Created August 9, 2024 05:04
Repair HEIF files produced by Sony cameras to show up with the correct orientation in iOS Photos.
#!/usr/bin/env bash
# Usage: ./fix-sony-heif /path/to/directory/with/photos
# Works by fixing EXIF rotation info and renaming .HIF to .HEIC.
# Based on discussion here: https://www.reddit.com/r/SonyAlpha/comments/173qnzg/comment/kr4dcoc/
if [ $# == 1 ]; then
cd $1
fi
exiftool '-Orientation<CameraOrientation' -ext hif * -r
# A solver for A-Puzzle-A-Day from https://www.thingiverse.com/thing:4876979
# Solutions are printed with terminal color escape sequences.
from typing import Dict, List, Tuple
import attrs
import numpy as np
import termcolor
@huzecong
huzecong / io-link-for-github-profile-page.js
Created April 3, 2020 15:32
A Tampermonkey userscript to display .github.io links on user's profile page. https://greasyfork.org/en/scripts/399423-io-link-for-github-profiles
@huzecong
huzecong / load_multiple_json_objects.py
Created April 1, 2020 19:22
Load multiple JSON objects from a single string, in linear time.
# 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 January 29, 2020 21:15
A snippet to remove the watermark from a certain PDF book. You'll still need to manually locate the watermark element though.
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 January 29, 2020 21:14
A snippet to guess the shoutkey for LTI colloquiums
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 September 1, 2023 18:24
A super-enhanced version of namedtuple that supports multiple inheritance and arbitrary field orders.
# Copyright (c) 2021 Zecong Hu
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR