Skip to content

Instantly share code, notes, and snippets.

View MilesCranmer's full-sized avatar

Miles Cranmer MilesCranmer

View GitHub Profile
from functools import lru_cache
@lru_cache # Stores previously computed factorials
def factorial(num):
if num < 2:
return 1
return num * factorial(num - 1)
def N(C, m_2, m_1, m_0):
count = 0
@MilesCranmer
MilesCranmer / num_tokens.sh
Created September 29, 2023 06:25
Easily count the number of tokens in text from the command line
function num_tokens {
prun python -c 'import sys; import tiktoken; s = "\n".join([line for line in sys.stdin]); encoding = tiktoken.get_encoding("cl100k_base"); print(len(encoding.encode(s)))'
}
# e.g., `echo "Hello World!" | num_tokens`
# this should give 3 tokens.
@MilesCranmer
MilesCranmer / startup.jl
Created May 28, 2025 18:36
Julia startup file with expanded shell mode compatibility
# ~/.julia/config/startup.jl
### REPL CUSTOMIZATION
isinteractive() && VERSION < v"1.13.0-" && @eval begin
"""
ShellSpecification{is_windows, shell}
A type used for dispatch to select the appropriate shell command preparation logic.
It is parameterized by `is_windows::Bool` indicating the operating system,
and `shell::Symbol` representing the basename of the shell executable.