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 <[email protected]>
import difflib
import itertools
import textwrap
import typing
def side_by_side(
left: typing.List[str],
@jlumbroso
jlumbroso / codePost-export-submission-links.py
Created May 10, 2022 00:26
codePost snippet to export a CSV file of the links to all submissions for a given assignment
@jlumbroso
jlumbroso / json_datetime.py
Created May 16, 2022 02:16
Simple, datetime-aware JSON encoding/decoding in Python.
# Copyright (c) 2022, Jérémie Lumbroso <[email protected]>
#
# Simple datetime-aware JSON in Python
#
# Usage:
# - json_timestamp_loads just() like json.loads()
# - json_timestamp_dumps just() like json.dumps()
import datetime
@jlumbroso
jlumbroso / gh_clone.sh
Created May 23, 2022 14:02
Introduces a command `gh` to clone your repos in a few keystrokes
# Fast command-line cloning of GitHub repos
#
# usage: add to your .bashrc or .zsh like this:
# source gh_clone.sh
# replace 'jlumbroso' with your own GitHub username
export GITHUB_USERNAME="jlumbroso"
# one-line repo clone
# gh <repo> [<-- will default to username=${GITHUB_USERNAME}]
@jlumbroso
jlumbroso / codePost-recompute-grades.py
Created September 17, 2022 16:50
codePost snippet to recompute the grades of all submissions of an assignment
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-assign-graders.py
Created November 28, 2022 01:51
codePost snippet to assign graders to specific submissions, given a CSV file
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 = "F2022"
ASSIGNMENT = "Final Project Proposal PDF"
DEFAULT_TEACHER = "[email protected]"
@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: ["[email protected]", "[email protected]"],
@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-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 / 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",