Skip to content

Instantly share code, notes, and snippets.

View dandrake's full-sized avatar

Dan Drake dandrake

View GitHub Profile
@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
Loading
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
#
@dandrake
dandrake / foundational_skills_and_concepts.md
Last active August 29, 2015 14:10
Foundational Skills & Concepts assignments

(a ROUGH DRAFT of something I'm considering for my linear algebra class next semester...)

What are these?

Every week you'll have an assignment intended to help you acquire and practice skills and concepts that are, well, foundational to the study of linear algebra. The ideas, procedures, and calculations in these assignments are essential to success in this course.

@dandrake
dandrake / mmm-sagetex.el
Last active June 13, 2019 08:47
Use MMM for SageTeX in emacs
;; add this to your .emacs / init.el to use mmm (multiple major modes) with SageTeX. This works with AUCTeX and
;; emacs 23.4. The fontification gets a little wonky, though; quotes inside a SageTeX environment throw
;; off the highlighting for the LaTeX bits that follow. But the modes correctly get switched.
;; if you don't have sage-mode installed, you can either (1) do "sage -i sage-mode" and follow the instructions to
;; enable it, or (2) replace sage-mode below with python-mode, which is good enough for regular editing of Sage code
(require 'mmm-auto)
(setq mmm-global-mode 'maybe)
@dandrake
dandrake / newton.sage
Created April 23, 2012 06:20
a Sage @interact for root finding with Newton's method
"""
My Newton's method Sage @interact. A reworked version of
http://wiki.sagemath.org/interact/calculus#Newton-Raphson_Root_Finding
by Neal Holtz, and which was in turn inspired by Marshall Hampton's
tangent line grapher.
This code is available as a published worksheet at
https://sagenb.kaist.ac.kr:8066/home/pub/53 and on the Sage cell server at
http://aleph.sagemath.org/?q=81e86e25-b27c-40c6-ac01-b7489b55e84e. (Note
that right now, you need to use
@dandrake
dandrake / auctex-synctex-evince.el
Created April 4, 2012 03:04
Make AUCTeX do forward and inverse search with SyncTeX and Evince
;; This is originally from
;; http://ubuntuforums.org/showthread.php?s=618526e60dfcf25e6413439603fa08ad&t=1716268&page=2.
;; Thanks to user "florenzen". I've included the fixes for Ubuntu 11.10
;; and wrapped buffer-file-name in a call to file-truename because
;; kpathsea/SyncTeX follow symlinks; see
;; http://tex.stackexchange.com/questions/25578/why-is-synctex-in-tl-2011-so-fussy-about-filenames.
;; Forward/inverse search with evince using D-bus.
(if (require 'dbus "dbus" t)
(progn