Skip to content

Instantly share code, notes, and snippets.

View dandrake's full-sized avatar

Dan Drake dandrake

View GitHub Profile
@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)
@dandrake
dandrake / flashlight.html
Created July 14, 2025 20:35
phone screen night vision red flashlight app as a single HTML page
<!--
You want to use your phone as a flashlight, but using the camera flash
is (1) too bright, and (2) is white and is jarring at night if you want
just a bit of dim light.
So you want, say, a dim, red light.
There are apps that turn your entire screen some color, but you don't
need that. Just transfer this HTML page to your phone and load it up in
@dandrake
dandrake / dtc-animate-crash.md
Created June 27, 2025 20:02
Don't Teach Coding animate crash

If you run

#lang dtc/frames/animations
(animate `(1 2 3))

as a script from the command line in Ubuntu 25.04, the result is:

invalid memory reference. Some debugging context lost
#!/usr/bin/env racket
;;;; Support code for my shell "gitcd" function: if you are in a git
;;;; repo, but not in the worktree part -- you're in a regular repo
;;;; somewhere inside the .git directory, or in a bare git repo -- the
;;;; usual "git rev-parse --show-toplevel" stuff doesn't work.
;;;;
;;;; The code here detects those situations where rev-parse fails: it
;;;; looks for either ".git" somewhere in the current directory's
;;;; ancestry, or "reponame.git" in the cwd ancestry.
;; Inspired by this blog post on "let's surround":
;; https://arialdomartini.github.io/emacs-surround-2 and
;; https://www.emacswiki.org/emacs/SurroundRegion.
;;
;; Notable bits:
;;
;; - Specifying =open= as a default value in the closing delimiter completing
;; read -- that allows the user to hit return to re-use the opening
;; delimiter for the closing one.
;; - This moves point accordingly, so that you can make repeated calls to
@dandrake
dandrake / not_code_just_a_note.md
Last active December 21, 2023 20:31
Using gist just to share simple notes?

A demo for a friend looking to share Evernote-style notes

You can write Markdown content and is should work as expected with links and such.

Moreoever, because this is github, there's git's revision control behind the scenes.

Here's a typo that I'll fix...click Edit in the top right, and edit away. Then see your changes in the Revisions tab from the upper left.

I even attached an image file: here it is.

"""
Print a "continuous" calendar -- as a ribbon / candy bar:
https://davidseah.com/node/compact-calendar/
https://docs.python.org/3/library/calendar.html
Example output:
>>> calendar.setfirstweekday(1)
>>> print(domonths(2023, 9, 6))
@dandrake
dandrake / my-mark-ring.el
Last active March 1, 2023 01:18
emacs personal mark ring
; Emacs has two mark rings: a buffer-local one, and a global one. I always get confused with them; my mental model
; is that there ought to be just one mark ring. I want to implement that without trampling over the existing mark
; ring stuff. Here's a first draft at doing so: I just add a hook so that anytime the mark is set, we append to
; my own personal mark ring, and then I have a function that is basically a copy-and-paste of pop-to-mark-command.
; This...seems to work? I am (1) stunned that it was so easy, and (2) suspcious that this ought to be unnecessary
; if I really understand the mark rings and used them correctly.
; Thanks to https://mathstodon.xyz/@[email protected] for pushing me to try this; see https://mathstodon.xyz/@[email protected]/109913166908490838
; and my replies.