Skip to content

Instantly share code, notes, and snippets.

View dandrake's full-sized avatar

Dan Drake dandrake

View GitHub Profile
;; 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/@vernon@emacs.ch for pushing me to try this; see https://mathstodon.xyz/@vernon@emacs.ch/109913166908490838
; and my replies.
@dandrake
dandrake / base_ten_base_T.py
Last active February 25, 2023 14:25
converting between "base ten" and "base T"
# Python code accompanying https://ddrake.prose.sh/base_ten_without_zero
def T_to_zero(Tnum):
"""Convert a number (provided as a string) written with "T" notation
to a Python integer, which by default is displayed using the
ordinary positional notation with "0".
"""
T_digit_to_int = {str(i): i for i in range(1, 10)}
T_digit_to_int['T'] = 10
return sum(10**p * T_digit_to_int[d] for p, d in enumerate(reversed(Tnum)))

Trice: a trick-taking dice game

Here are the rules for what I call Trice -- it's a trick-taking dice game. The name comes from trick-taking, and that it plays quickly.

Setup

  • The game is usually played with 4 players, but generalizes to 2+.
  • You'll need sets of dice in different colors/patterns -- one for each player. The recommended set is the "standard D&D set": d4, 3d6, d8,
select * from THINGS_IM_GONNA_DO where
thing = "give you up" or
thing = "let you down" or
thing = "run around and desert you" or
thing = "make you cry" or
thing = "say goodbye" or
thing = "tell a lie and hurt you";
select count(*) from problems;
99
@dandrake
dandrake / ddrake-condvar.c
Created October 18, 2020 13:43
pthread condition variables API, waking up multiple threads
/* Like join.c, but I want to see if multiple threads can wait on a single
condition. It looks like `pthread_cond_broadcast` is the API function for this.
What's weird is that this has some kind of race condition in it. I've seen:
* only the parent woken up
* parent and child2 woken up
* child2 woken up twice!
*/
@dandrake
dandrake / Cheryl, eigenvalues, eigenvectors.ipynb
Last active August 29, 2015 14:21
Cheryl, eigenvalues, eigenvectors
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dandrake
dandrake / gist:6fa2f03b5dff632706a9
Created December 31, 2014 01:25
get a list of row operations / elementary matrices that reduce a matrix to rref
# Sage has a built-in rref() method for matrices, but sometimes when
# teaching it's nice to get a list of the row operations you would do to
# put the matrix into rref -- or, equivalent, a list of the
# corresponding elementary matrices.
#
# This script contains two functions along those lines:
#
# rref(): returns a list of elementary matrices that put the matrix into rref
# rref_steps(): returns a list of strings that describe what row ops to do
#