This file contains 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
from talon import Context, Module, actions | |
from typing import List, Optional, Union, Iterator | |
mod = Module() | |
ctx = Context() | |
digits = "zero one two three four five six seven eight nine".split() | |
teens = "eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen".split() | |
tens = "ten twenty thirty forty fifty sixty seventy eighty ninety".split() | |
scales = "hundred thousand million billion trillion quadrillion quintillion sextillion septillion octillion nonillion decillion".split() |
This file contains 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
@mod.capture(rule="<user.letter> | <user.number_key> | <user.symbol_key> | ship <user.letter>") | |
def char(m) -> str: | |
"""A single character.""" | |
if m[0] == "ship": return m.letter.upper() | |
return str(m) | |
@mod.capture(rule="<user.char_chunk>+") | |
def chars(m) -> str: | |
"""A sequence of characters, spelled out.""" | |
return "".join(m.char_chunk_list) |
This file contains 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
# two folks have different preferences if one likes a beer the other doesn't. | |
differ(a, b) :- person(b), likes(beer, a), !likes(beer, b). | |
differ(a, b) :- person(a), !likes(beer, a), likes(beer, b). | |
# what you want to write | |
unique(a) :- ∀b. (a = b or differ(a,b)). | |
# how you have to write it. | |
unique(a) :- not exists_same(a). | |
exists_same(a) :- person(a), person(b), !differ(a,b), a != b. |
This file contains 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
from talon import Context, Module, actions, speech_system | |
from talon import speech_system | |
from talon.lib import flac | |
from talon_init import TALON_HOME | |
import os | |
import struct | |
import wave | |
from datetime import datetime | |
ALWAYS_RECORD = True |
This file contains 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
from talon import Module, Context, actions | |
delimiters = {x[0]: x[1] for x in "() [] {} <> “”".split()} | |
mod = Module() | |
@mod.action_class | |
class Actions: | |
def delimiter_close(delimiter: str) -> str: | |
"""Turns a delimiter into its corresponding closing delimiter.""" | |
return delimiters.get(delimiter, delimiter) |
This file contains 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
# this will work with python 3, but probably not python 2 | |
from functools import reduce | |
class BoolSemi: | |
zero = False | |
one = True | |
def plus(x, y): | |
return x or y | |
def times(x, y): | |
return x and y |
This file contains 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
(* Inlining for the λ-calculus, implemented in tagless final style. This seems | |
* like it _must_ be related to Normalization By Evaluation (see eg [1,2]), | |
* since they both amount to β-reduction (plus η-expansion in extensional NBE), | |
* and the techniques have a similar "flavor", but I don't immediately see a | |
* formal connection. | |
* | |
* [1] https://gist.github.com/rntz/f2f15f6cb4b8690c3599119225a57d33 | |
* [2] http://homepages.inf.ed.ac.uk/slindley/nbe/nbe-cambridge2016.pdf | |
*) |
This file contains 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
\documentclass{article} | |
\RequirePackage{hyperref} | |
\RequirePackage{silence} | |
\begin{document} | |
\section{\ensuremath{\mathbf{foo}}} | |
\end{document} |
This file contains 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
-- I'm honestly slightly perturbed that this works. | |
-- Adapted from code in the `timeit` package. | |
-- Returns the time in seconds it took to evaluate the argument. | |
-- Of course, if the argument thunk was already forced, this will be small. | |
foo :: a -> IO Double | |
foo x = do | |
t1 <- getCPUTime | |
t2 <- seq x getCPUTime | |
return (fromIntegral (t2-t1) * 1e-12) |
This file contains 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
%% This recreates the abstract from "The Concept of a Meta-Font" by Don Knuth, | |
%% https://s3-us-west-2.amazonaws.com/visiblelanguage/pdf/16.1/the-concept-of-a-meta-font.pdf | |
%% | |
%% Observe that "modern" Computer Modern as rendered in a PDF viewer(*) is much | |
%% lighter in weight (has much thinner strokes) than Computer Modern as printed | |
%% in 1982. | |
%% | |
%% (*) In my case, evince 3.30.1 on Ubuntu Linux 18.10 on a 4K screen in 2019. | |
%% Different PDF viewers on different operating systems and different screens | |
%% may have different font rendering behavior - in particular, I have heard that |