Skip to content

Instantly share code, notes, and snippets.

@braised-babbage
braised-babbage / test.c
Created July 1, 2021 17:30
ecl uncaught condition
/* build and run: clang test.c -lecl -o test && ./test
output:
Condition of type: SIMPLE-ERROR
msg
No restarts available.
Top level in: #<process TOP-LEVEL 0x106c1af80>.
> ^D
(defun sample-variance (xs)
"Compute the sample variance of a list XS in a single pass. Just don't ask any questions..."
(loop :with sum := 0
:with sum-of-squares := 0
:for x :in xs
:for i :from 1
:do (incf sum x)
(incf sum-of-squares (expt x 2))
:finally
(return (/ (- sum-of-squares (/ (expt sum 2) i))
from collections import defaultdict
import numpy as np
from typing import Dict, Any, List, Union, Callable, Set, Iterable, Iterator, Optional, Tuple
from dataclasses import dataclass
@dataclass
class Image:
""" Representation of an image, along with metadata. """
import requests
API_ENDPOINT = "https://psg.gsfc.nasa.gov/api.php"
EXAMPLE_CONFIG = "/Users/erik/Desktop/pspec/config.txt"
# NOTE: kwargs are explained here https://psg.gsfc.nasa.gov/helpapi.php
def get_spectra(config_path, **kwargs):
with open(config_path, 'r') as f:
kwargs['file'] = f.read()
#!/bin/bash
# install texlive dependencies
yum install -y perl-Tk perl-Digest-MD5
# download texlive installer
wget http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz
tar xzf install-tl-unx.tar.gz
# HACK pulling texlive profile from my github
wget https://gist.githubusercontent.com/kilimanjaro/b876f13ffdcd5557aa9fc6660e6fe7b0/raw/4247c52e555190d97e753a9ec7970d933cc898a3/texlive.profile
# install from profile
@braised-babbage
braised-babbage / texlive.profile
Last active December 9, 2019 18:42
texlive profile
# texlive.profile written on Mon Dec 9 18:40:07 2019 UTC
# It will NOT be updated and reflects only the
# installation profile at installation time.
selected_scheme scheme-custom
TEXDIR /usr/local/texlive/2019
TEXMFCONFIG ~/.texlive2019/texmf-config
TEXMFHOME ~/texmf
TEXMFLOCAL /usr/local/texlive/texmf-local
TEXMFSYSCONFIG /usr/local/texlive/2019/texmf-config
TEXMFSYSVAR /usr/local/texlive/2019/texmf-var
@braised-babbage
braised-babbage / einsum_compiler.py
Last active November 12, 2019 17:42
Translate a pyquil program to a single einsum call
## einsum_compiler.py
##
## What it is
## ----------
##
## Numpy has a standard function, einsum, which can be used to evaluate large
## nested summations. Here we show how to translate a pyQuil program consisting
## of only gate applications to a single einsum call.
##
##
@braised-babbage
braised-babbage / tictactoe.py
Created May 7, 2019 04:12
a simple game of tic-tac-toe
from dataclasses import dataclass
from typing import Tuple
PLAYER_X = 'X'
PLAYER_O = 'O'
EMPTY = ' '
def other(player):
@braised-babbage
braised-babbage / 3sat.py
Created April 22, 2019 02:41
looking at 3-SAT phase transitions
from itertools import product
import random
def random_clause(vars):
"""Return a random 3-SAT clause."""
clause_vars = random.choices(vars, k=3)
modifiers = random.choices(["", "not "], k=3)
exprs = [f"{v}{x}" for x,v in zip(clause_vars, modifiers)]
clause = " or ".join(exprs)
return clause
@braised-babbage
braised-babbage / regex.py
Created March 30, 2019 22:46
Regular Expressions in Python
"""Regular expression parser and interpreter.
One may check whether a string s matches a regular expression r by using the
`matches` function. To construct a regular expression object from its compact
textual form, use the `parse` function.
As a combined example,
>>> r = parse("a|b*(c)")
>>> matches(r, "bbbc")