This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Generate a random token. | |
| """ | |
| # After reading Zooko's, I was like oops, I'm an idiot. | |
| # I should probably use his, but anyway here's a fix: | |
| # correct cryptogen.sample() to cryptogen.choice(). | |
| import math | |
| from random import SystemRandom |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| machine = assignment*. | |
| assignment = lvalue _? '=' _? expr _? '\n'. | |
| expr = lvalue _ lvalue _ lvalue. | |
| lvalue = name ('.' literal)*. | |
| literal = '0' | '1' | name. | |
| name = /[^.]+/. | |
| _ = /\s+/. | |
| comment = /#.*/. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Not a venture capitalist, a version control thingy. | |
| https://hackpad.com/Make-a-Local-Version-Control-System-qUPsMncVjBx | |
| """ | |
| import datetime, itertools, os, re, shutil, sys | |
| def main(argv): | |
| if len(argv) < 2: | |
| print 'usage XXX' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| superseded by https://github.com/darius/sketchbook/blob/master/trees/bplustrees.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Given a sorted array A[:n] with no dups, which has been rotated by some r, | |
| 0 <= r < n, find r in O(n lg n) time. | |
| i.e. Return r such that A[r:] + A[:r] is sorted. | |
| """ | |
| def unrotate(A): | |
| lo, hi = 0, len(A) | |
| while lo+1 < hi: | |
| if lo+2 == hi: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "Erase that part of the log not yet written to the logfile." | |
| (setq keylogger-events '())) | |
| (defun keylogger-log () | |
| ;; (Would be `with-demoted-errors' instead if not for paranoia from | |
| ;; an actual user.) | |
| (ignore-errors | |
| (when (and (this-command-keys) | |
| (keylogger-loggable-p)) | |
| (push (vector (current-time) major-mode (this-command-keys)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; Record all keystrokes, with timestamps at millisecond resolution. | |
| ;;; (Actually it's Emacs commands instead of keystrokes, but that's close enough.) | |
| ;;; Restricted to particular modes, but I really advise NOT RUNNING | |
| ;;; THIS AT ALL if you do much of anything sensitive inside Emacs. | |
| (defvar keylogger-path "/home/darius/git/keystroke-analysis/emacs-key-log" | |
| "Where to store the log.") | |
| (defvar keylogger-major-modes '(text-mode) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; Track the recent typing rate to see whether it exceeds a target rate, using | |
| ;; a method vaguely like https://en.wikipedia.org/wiki/Exponential_smoothing | |
| ;; Here's the scheme: We keep track of a smoothed rate. Each keystroke | |
| ;; increases it by 1; each second that passes multiplies it by a decay | |
| ;; factor less than 1. To deal with noninteger time intervals, the | |
| ;; decaying actually happens smoothly as an exponential in time. | |
| ;; This method has the disadvantage that the estimated rate just after | |
| ;; a keystroke is always >=1, which is 60/5 = 12wpm. The lower the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (setq target-cps 5.0) | |
| (setq smoothed-rate 0) | |
| (setq last-stroke-time 0) | |
| (set-hook '(lambda () | |
| (let ((now (current-time))) | |
| (setq smoothed-rate (+ 1 (decay-smoothed-rate now))) | |
| (setq last-stroke-time now)))) | |
| (set-time '(lambda () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; Character codes from https://en.wikipedia.org/wiki/Block_Elements | |
| (defconst barchart--bar-chars [32 #x258f #x258e #x258d #x258c #x258b #x258a #x2589 #x2588]) | |
| (defun barchart-make-bar (length fraction) | |
| "Return a string of the given length that looks like a | |
| horizontal bar representing a real number between 0 and 1 (the | |
| fraction)." | |
| (assert (<= 0 fraction 1)) | |
| (let ((f (* fraction length)) | |
| (chars '())) |