Skip to content

Instantly share code, notes, and snippets.

@jlewin
jlewin / dumpPow.js
Created August 24, 2024 18:23
Quickly visualize a powers of a given base
function dumpPow(b, e) {
const steps = [];
console.log(`Raise ${b} to ${e}`);
for(let j = 0; j <= e; j++) {
const v = Math.pow(b, j);
const len = v.toString().length;
steps.push({
@jlewin
jlewin / QuizletPrint.js
Created December 18, 2023 23:29
Quizlet Print Revisions
// ==UserScript==
// @name QuizletPrint
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Cleanup for quizlet print
// @author John Lewin
// @match https://quizlet.com/*
// @grant none
// ==/UserScript==
@jlewin
jlewin / extractQuestions.js
Last active May 24, 2023 22:54
Canvas Quiz to Quizlet Import
// Extracts the content of textNode children, skipping descendant elements
function getTextContent(e) {
return [...e.childNodes] // has childNodes inside, including text ones
.filter(child => child.nodeType === 3) // get only text nodes
.filter(child => child.textContent.trim()) // eliminate empty text
.map(textNode => textNode.textContent) // extract text content
.join('').trim();
}
// Selects either the .answer_html, .answer_text, or textContent of the given element
@jlewin
jlewin / AddPlaylist.js
Created February 1, 2023 07:03
Add playlist support to list of links in Canvas
var lastNode = null;
var video = document.createElement('iframe');
video.setAttribute('name','jlFrame');
video.style = `display: block;
width: 1900px;
float: right;
position: absolute;
right: 0px;
min-height: 100vh;
top: 0px;
@jlewin
jlewin / quick-espresso-offerup-filter.js
Created August 27, 2022 20:24
Filter OfferUp results
// Drop undesired items
var removeList = ['Nespresso', 'Vertuo', 'Delonghi', 'De’Longhi', "De'longhi", 'Gevi', 'Calphalon', 'Ascaso', 'Mr ', 'Mr.', 'Krups', 'Keurig','Chefman','Conqueco', 'CBTL', 'Mattina', 'Terra', 'Smeg', 'EspressoWorks', 'Arlime', 'Bambino'];
// Remove matching results (and ads)
var links = Array.from(document.querySelectorAll('a'));
links.filter(l => l.href.includes('bing.com') ||
(l.href.includes('/item/detail') &&
removeList.some(r => l.title.toLowerCase().includes(r.toLowerCase()))))
.forEach(e => e.parentElement.removeChild(e));
@jlewin
jlewin / gist:f92d3d2ba36e8d5a8187b700f74787f4
Created May 24, 2022 17:14
Filter Canvas/Pearson grades to non-perfect scores
document.querySelectorAll(".screenreader-only").forEach(e => e.remove());
document.querySelectorAll('#grades_summary tr.student_assignment').forEach(r => {
if (r.cells[3].innerText === r.cells[4].innerText) {
r.style.display = 'none';
}
});
@jlewin
jlewin / convert-tiff-to-jpg.cmd
Created July 20, 2021 01:04
Works on my machine
FOR /R %a IN (*.tif) DO magick convert "%~a" -quality 100 "%~dpna.jpg"
@jlewin
jlewin / serialize_dbset_without_error.cs
Created January 13, 2021 20:22
Serialize EF dbset - quickly adapt action method to dump dbset to json without serializing virtual navigation props
// As described in https://stackoverflow.com/q/26162902/84369
public ActionResult Index()
{
var sketches = db.Sketches.Include(p => p.Board);
// Serializer settings
var settings = new JsonSerializerSettings
{
ContractResolver = new CustomResolver(),
PreserveReferencesHandling = PreserveReferencesHandling.None,
@jlewin
jlewin / jwt.cs
Created January 9, 2021 22:14
JWT signature compute in c#
// From stackoverflow and adapted to unusure it makes sense with our data
// -- https://stackoverflow.com/questions/38725038/c-sharp-how-to-verify-signature-on-jwt-token
void Main()
{
var jwt = "some-jwt";
var segments = jwt.Split('.');
var decoded = segments.Select(s => System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(s)));
@jlewin
jlewin / serialize_timespan.py
Created June 25, 2020 04:31
Basic tests to for timespan serialization
Python 2.7.16 (v2.7.16:413a49145e, Mar 4 2019, 01:37:19) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime, timedelta
# Store start
>>> start = datetime.now()
# Get timespan by subtracting start from now
>>> elapsed = datetime.now() - start