Skip to content

Instantly share code, notes, and snippets.

View kevinlin1's full-sized avatar

Kevin Lin kevinlin1

View GitHub Profile
@kevinlin1
kevinlin1 / LinkedList.java
Last active July 11, 2023 19:22
Learning reference semantics through front and end linked list manipulations.
// Implementer writes this class.
// We haven't written "implements List<E>" (later we might write in the AbstractList)
public class LinkedList<E> {
// Both front and back are class invariants!
// The implementer must always ensure between method calls that
// front points to the first node
// and back points the last node!
// Reference to the first node in the sequence.
private Node front;
@kevinlin1
kevinlin1 / ArrayList.java
Last active July 10, 2023 19:43
Applying class invariants to address a bug in ArrayList.toString.
// There are a lot of methods needed to implement List!
// Abstract classes like AbstractList make this easier!
import java.util.AbstractList;
// Implementer writes this class.
public class ArrayList<E> extends AbstractList<E> {
private E[] elementData;
private int size;
public ArrayList() {
@kevinlin1
kevinlin1 / Account.java
Last active July 8, 2023 23:53
Understanding object-oriented programming as interface design and engineering.
// This code is written by the implementer.
// In addition to the compareTo function, we also write "implements Comparable<...>" to
// indicate to Java that this class satisfies the contract for Comparable.
public class Account implements Comparable<Account> {
// Private prevent other classes from accessing or modifying these fields
private String holder;
private double balance;
// In Python, we write "self" to indicate the current object.
// In Java, we write "this" to indicate the current object. Note that the parameter
@kevinlin1
kevinlin1 / Demo.java
Last active July 3, 2023 21:32
Translating Python to Java: from count_values to countValues
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
public class Demo {
// Return type Argument type
public static List<Integer> countValues(Map<Integer, List<Integer>> entries) {
// result = []
@kevinlin1
kevinlin1 / canvas_sync.py
Last active June 12, 2023 15:19
Bulk-update grades in Canvas based on student progress in the Ed learning management system. Requires: aiohttp[speedups] canvasapi nest_asyncio pandas requests
import aiohttp
import asyncio
import canvasapi
import itertools
import json
import pandas as pd
import requests
import nest_asyncio
nest_asyncio.apply()
@kevinlin1
kevinlin1 / random-canvas-group.js
Created March 3, 2023 17:23
Randomly select a Canvas group from the instructor-side page listing all available Canvas groups. Hides the unassigned students sidebar and scrolls the randomly-selected team into view.
javascript:(() => {
document.querySelector('.unassigned-students').remove();
document.querySelector('.groups').classList.remove('span9');
document.querySelectorAll('[aria-expanded="true"].toggle-group.group-heading').forEach(e => e.click());
const groups = document.getElementsByClassName('toggle-group group-heading');
const randomGroup = groups[Math.floor(Math.random() * groups.length)];
randomGroup.click();
randomGroup.scrollIntoView();
#!/usr/bin/env python3
from canvasapi import Canvas
import os
if __name__ == "__main__":
canvas = Canvas("https://canvas.uw.edu", os.getenv("TOKEN"))
course = canvas.get_course(os.getenv("COURSE_ID"))
groups = course.get_groups()
#!/usr/bin/env python3
from canvasapi import Canvas
import os
if __name__ == "__main__":
canvas = Canvas("https://canvas.uw.edu", os.getenv("TOKEN"))
course = canvas.get_course(os.getenv("COURSE_ID"))
groups = course.get_groups()
@kevinlin1
kevinlin1 / autocaption.js
Last active April 25, 2024 20:19
Caption your speech on any website using the Web Speech API. Supports all browsers except for Firefox. To start captioning speech, add this script as a bookmarklet (paste contents in the URL field with "javascript:" at the beginning) and run the bookmark. To stop captioning speech, click the caption box.
javascript:(() => {
const div = document.createElement('div');
div.style.alignItems = 'flex-end';
div.style.backgroundColor = 'black';
div.style.top = '0';
div.style.color = 'white';
div.style.display = 'none';
div.style.fontFamily = 'Google Sans';
div.style.fontSize = '3vh';
div.style.lineHeight = '4vh';
@kevinlin1
kevinlin1 / canvas_lesson_sync.ipynb
Last active April 2, 2023 00:45
Synchronize Canvas assignments with Ed Lesson completions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.