Skip to content

Instantly share code, notes, and snippets.

View dandrake's full-sized avatar

Dan Drake dandrake

View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>A simple, accessible version of Bloom's taxonomy</title>
<meta name="description" content="Bloom's taxonomy of cognitive levels as accessible HTML and CSS: a WCAG-conformant replacement for the common pyramid diagram, which fails contrast and is unreadable by screen readers.">
<style>
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

Displaying Images in Tkinter: PNG vs JPG

The Simple Case: PNG Files with tk.PhotoImage

Tkinter has built-in support for a few image formats — PNG, GIF, and PPM/PGM — through tk.PhotoImage. For a PNG file, no third-party library is needed:

import tkinter as tk
@dandrake
dandrake / display_image_with_tkinter.py
Created April 20, 2026 17:44
simplest way to display an image in a Python tkinter program
import tkinter as tk
def main():
win = tk.Tk()
win.geometry("400x200")
label = tk.Label(win, text="Here is an image.")
label.grid(row=0, column=0)
my_tk_photoimage = tk.PhotoImage(file="your_image_here.png")
@dandrake
dandrake / pandoc_lua_filters_for_stripping_speaker_notes.md
Last active January 28, 2026 22:14
Basic pandoc usage of Lua filters to remove speaker notes, html comments from output

Motivation: removing speaker notes from slides

I make reveal.js slides with markdown and convert with pandoc. Sometimes I want to post those slides so my students can access them, but I want to strip out the speaker notes because they usually aren't very useful to them.

Solution: use a pandoc filter

I don't want to edit my source files; I just want the output correct. So, I could do something to the output html slides.

But: I also want to allow for the possibility that I'll want to output to other formats. So the best solution is to tell pandoc to do that filtering while it converts.

@dandrake
dandrake / do-command-other-window.el
Last active December 9, 2025 20:59
"do command in other window" emacs lisp
(defun my/do-command-other-window (count command &optional return-p)
"Do COMMAND in other-window. The COUNT argument is provided to
`other-window'.
The optional RETURN-P argument, if true, will make this return to the
original window after calling COMMAND.
The intended way to use this function is by calling it from an
interactive function that specifies the command:
@dandrake
dandrake / Coffee.java
Created November 21, 2025 20:29
Java enum example -- they are class instances and can have fields/state and behavior/methods
public enum Coffee {
ESPRESSO(2.50, 2),
LATTE(4.50, 8),
CAPPUCCINO(4.00, 8),
AMERICANO(3.00, 8);
// the 'final' isn't necessary functionally, since you can't change these from outside the class/enum
// but this does document our intent, and would prevent accidentally adding something inside this enum
// that modified the field.
private final double price;
@dandrake
dandrake / steve_reich_clapping_sonic_pi.rb
Last active October 22, 2025 21:13
Sonic Pi code for Steve Reich's "Clapping"
# my version of Steve Reich's Clapping for Sonic Pi:
# https://en.wikipedia.org/wiki/Clapping_Music
# https://youtu.be/lzkOFJMI5i8?si=oaBTc4WBR_DC2SJJ
# https://sonic-pi.net/
use_bpm 120
claps = [1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0].ring
live_loop :clapping do
@dandrake
dandrake / racket-parameters-debug-print-indentation.rkt
Last active August 10, 2025 12:59
Parameters in Racket for debug-printing in recursive functions
#lang racket
#|
I'm trying to understand parameters in Racket.
One idea: for a recursive function,
have a parameter that says how much to indent a debugging print
statement so that I can see the call stack more clearly.
@dandrake
dandrake / README.md
Last active July 26, 2025 19:22
macro for defining constant / immutable variables in Racket

A macro that creates constants in Racket

Inspired by this Racket discourse post I tried writing a macro that defines bindings that work like constants in Racket.

Note that the solution here handles using set!; you can't prevent shadowing or redefining these variables -- see the Discourse thread.

@dandrake
dandrake / exercism-pythagorean-triplets.rkt
Last active July 26, 2025 19:15
Exercism's "Pythagorean triplets with given perimeter" Racket problem
#lang racket/base
;; This is lovely but Exercism doesn't let you (require math)!
;;
;; Posted this: https://gist.github.com/dandrake/d9a3e20021a68ed16bce6f5dc79e62eb
(require racket/contract)