Skip to content

Instantly share code, notes, and snippets.

@kilimanjaro
kilimanjaro / test.c
Created Jul 1, 2021
ecl uncaught condition
View test.c
/* 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
View single-float-woes.lisp
(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))
View simple_pipeline.py
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. """
View api.py
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()
View latex.sh
#!/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
View 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
@kilimanjaro
kilimanjaro / einsum_compiler.py
Last active Nov 12, 2019
Translate a pyquil program to a single einsum call
View einsum_compiler.py
## 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.
##
##
@kilimanjaro
kilimanjaro / tictactoe.py
Created May 7, 2019
a simple game of tic-tac-toe
View tictactoe.py
from dataclasses import dataclass
from typing import Tuple
PLAYER_X = 'X'
PLAYER_O = 'O'
EMPTY = ' '
def other(player):
@kilimanjaro
kilimanjaro / 3sat.py
Created Apr 22, 2019
looking at 3-SAT phase transitions
View 3sat.py
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
@kilimanjaro
kilimanjaro / regex.py
Created Mar 30, 2019
Regular Expressions in Python
View regex.py
"""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")