Skip to content

Instantly share code, notes, and snippets.

View jlumpe's full-sized avatar

Jared Lumpe jlumpe

View GitHub Profile
@jlumpe
jlumpe / pp_export.js
Created May 13, 2019 22:17
Tampermonkey script for fast BibTeX export in Paperpile app
// ==UserScript==
// @name Paperpile BibTeX export button
// @version 0.1
// @author Jared Lumpe
// @match http*://paperpile.com/app
// @grant unsafeWindow
// ==/UserScript==
(function() {
'use strict';
@jlumpe
jlumpe / makepackage.sh
Last active November 10, 2022 00:04
My set of custom LaTeX macros
#!/bin/bash
# Create and install tex package for macros
set -ex
TEXMFHOME=`kpsewhich -var-value=TEXMFHOME`
dir="$TEXMFHOME/tex/latex/custom"
mkdir -p "$dir"
./mathmacros.py sty > "$dir/mymath.sty"
@jlumpe
jlumpe / betterjsonencoder.py
Created June 29, 2017 19:29
Python JSON encoder that makes more of an effort to encode non-builtin types
from json import JSONEncoder
from numbers import Integral, Real
from collections.abc import Sequence, Mapping
class BetterJSONEncoder(JSONEncoder):
"""JSON encoder that makes more of an effort to encode non-builtin types."""
def default(self, o):
@jlumpe
jlumpe / forest.py
Last active June 23, 2023 21:37
Python class for a mutable set of trees with indexed nodes containing arbitrary data.
from collections.abc import MutableMapping, Set
class SetProxy(Set):
"""Read-only proxy for a set type."""
def __init__(self, set_):
self._set_ = set_
def __len__(self):
@jlumpe
jlumpe / bijection.py
Last active July 29, 2022 08:47
Bijection class in Python (aka bidirectional dictionary).
"""
A simple implementation of a bijection, which can be thought of as a
bidirectional ``dict``.
Author: Jared Lumpe
"""
from collections import Set, MutableMapping, Hashable
@jlumpe
jlumpe / netflix_ratings.py
Created July 29, 2016 04:44
Scrape Netflix ratings
"""https://www.netflix.com/MoviesYouveSeen"""
from bs4 import BeautifulSoup
def parse_rating(li):
rating = dict()
title_elem, = li.select('div.title > a')
rating['title'] = title_elem.text
@jlumpe
jlumpe / npy_info.py
Created July 13, 2016 04:42
.npy info #numpy
import struct, ast
def npy_info(fh):
"""Get information about a .npy file, without reading in all the data.
See http://docs.scipy.org/doc/numpy/neps/npy-format.html
"""
# Check magic number
if fh.read(6) != b'\x93NUMPY':