Skip to content

Instantly share code, notes, and snippets.

View jlumbroso's full-sized avatar

Jérémie Lumbroso jlumbroso

View GitHub Profile
@jlumbroso
jlumbroso / diff_side_by_side.py
Created May 8, 2022 02:18
Side-by-Side Diff Comparison in Python
# Code licensed LGPLv3 by Jérémie Lumbroso <lumbroso@cs.princeton.edu>
import difflib
import itertools
import textwrap
import typing
def side_by_side(
left: typing.List[str],
@jlumbroso
jlumbroso / publish_to_gh_pages.sh
Created February 14, 2024 03:06
Script to push a folder (such as the output of a static website generator) directly to a branch (such as "gh-pages") of a repository.
#!/bin/bash
###################################################################################
# Automatic gh-pages site updater
#
# Author: Jérémie Lumbroso <lumbroso@seas.upenn.edu>
# Date: February 13, 2024
#
# This script automates updating a GitHub Pages site hosted on the gh-pages branch
# of a repository. It takes a local folder containing the static site content and
@jlumbroso
jlumbroso / combine_for_model.py
Created February 12, 2024 22:15
A Python script to concatenate source code to send to a foundational model as a prompt.
#!/usr/bin/env python3
"""
combine_for_model.py
Author: Jérémie Lumbroso <lumbroso@seas.upenn.edu>
Date: July 25, 2023
Version: 1.0
Description:
@jlumbroso
jlumbroso / decrypt_all_pdfs.py
Created November 3, 2023 21:59
A Python script to recursively decrypt PDF files using `qpdf --decrypt`, handling files without passwords and overwriting the originals if decryption is successful.
#!/usr/bin/env python3
"""
decrypt_all_pdfs.py
Author: Jérémie Lumbroso <lumbroso@seas.upenn.edu>
Date: November 3, 2023
Description:
This script recursively finds all PDF files within a specified directory path,
checks if they are encrypted (without a password), and attempts to decrypt them
@jlumbroso
jlumbroso / unicode_logic_to_latex.py
Created October 23, 2023 19:56
Snippet to convert between Unicode and LaTeX representations of logical propositions.
import re
_LATEX_POST_ENTITY = "{}"
# Mapping of Unicode characters to LaTeX expressions
MAPPING = {
"∀": "\\forall",
"∃": "\\exists",
"→": "\\rightarrow",
"↔": "\\leftrightarrow",
@jlumbroso
jlumbroso / genanki-media-test.py
Created September 23, 2018 14:23
Minimal example of how to create a working Anki deck with a media file embedded.
import genanki
my_model = genanki.Model(
1380120064,
'Example',
fields=[
{'name': 'Object'},
{'name': 'Image'},
],
templates=[
@jlumbroso
jlumbroso / genanki-media-test.py
Created September 23, 2018 04:55
Minimal example to build an Anki deck with an image, with genanki
import genanki
my_model = genanki.Model(
1380120064,
'Example',
fields=[
{'name': 'Object'},
{'name': 'Image'},
],
templates=[
@jlumbroso
jlumbroso / codePost-compute-grade-from-file-contents.py
Created May 12, 2023 23:33
codePost snippet to automatically compute a grade based on extracting data from one of the files of the submissions (such as an auto-grader output), finalize all submissions of an assignment, and automatically add a comment that sets the grade of the submission
import re
import codepost
# ================================================================
# VARIABLE PARAMETERS
# get the API key here: https://codepost.io/settings
API_KEY = "... see above where to get this ..."
COURSE_NAME = "COS126"
COURSE_TERM = "S2023"
ASSIGNMENT = "Atomic"
@jlumbroso
jlumbroso / codePost-output-submission-dates.py
Last active February 20, 2023 23:14
codePost snippet to programmatically dump all the submission times (in UTC) for all submissions of an assignment in a CSV file
import codepost
# fancy progress bar if available
try:
from tqdm import tqdm
except ModuleNotFoundError:
# dummy replacement that does nothing
tqdm = lambda x: x
# variable parameters
@jlumbroso
jlumbroso / codePost-fix-partners.py
Last active December 1, 2022 03:18
codePost snippet to programmatically reassign students/partnerships on already-uploaded submissions
import codepost
# variable parameters
# get the API key here: https://codepost.io/settings
API_KEY = "... see above where to get this ..."
# mapping a codePost ID to students
# (note that this could be loaded from a CSV file)
partnerships = {
65490: ["student1@princeton.edu", "student2@princeton.edu"],