Skip to content

Instantly share code, notes, and snippets.

View liamtoney's full-sized avatar

Liam Toney liamtoney

View GitHub Profile
@gwerbin
gwerbin / conda_env_export.py
Last active August 28, 2024 12:13
Export a Conda environment with --from-history, but also append Pip-installed dependencies
"""
Export a Conda environment with --from-history, but also append
Pip-installed dependencies
Exports only manually-installed dependencies, excluding build versions, but
including Pip-installed dependencies.
Lots of issues requesting this functionality in the Conda issue tracker,
e.g. https://github.com/conda/conda/issues/9628
@PawaritL
PawaritL / example_input.py
Last active October 26, 2022 07:13
Converts a GeoJSON polygon to its antimeridian-compatible constituent polygon(s)
geojson = {
"type": "Polygon",
"coordinates": [
[
[179.0, 0.0],
[-179.0, 0.0],
[-179.0, 1.0],
[179.0, 1.0],
[179.0, 0.0]
]
@shawnbot
shawnbot / README.md
Last active July 20, 2024 19:18
50 US states as JSON

How this was made

  1. Visit the list of U.S. state abbreviations on Wikipedia.

  2. Sort the table by "status of region" to group the states together

  3. Select the cells of all of the states (from "Alabama" to "Wyo.") and press ⌘C to copy

  4. Cut the TSV in your clipboard to two columns (name and two-letter code)

    pbpaste | cut -d$'\t' -f1,4 | pbcopy
@kelvinn
kelvinn / InstallPythonGDAL.md
Last active July 28, 2024 14:08
Installing GDAL (Python 3.6) on Mac OS X

How-To: Install GDAL Python Bindings

I've found two ways to install the GDAL Python bindings on Mac.

Via GDAL Framework / QGIS

First, you can install the GDAL Framework via QGIS (or get it directly), and then do...

@Susensio
Susensio / numpy_lru_cache.md
Last active November 6, 2024 13:25
Make function of numpy array cacheable

How to cache slow functions with numpy.array as function parameter on Python

TL;DR

from numpy_lru_cache_decorator import np_cache

@np_cache()
def function(array):
 ...
@CarstenSchelp
CarstenSchelp / plot_confidence_ellipse.py
Last active August 21, 2024 17:19
A function to plot the confidence ellipse of the covariance of a 2D dataset. Uses matplotlib.
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
import matplotlib.transforms as transforms
def confidence_ellipse(x, y, ax, n_std=3.0, facecolor='none', **kwargs):
"""
Create a plot of the covariance confidence ellipse of `x` and `y`
See how and why this works: https://carstenschelp.github.io/2018/09/14/Plot_Confidence_Ellipse_001.html
@drawveloper
drawveloper / compress-pdf-with-gs.md
Created August 30, 2013 14:39
Compress PDF files with ghostscript

This can reduce files to ~15% of their size (2.3M to 345K, in one case) with no obvious degradation of quality.

ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

Other options for PDFSETTINGS:

  • /screen selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting.
  • /ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting.
  • /printer selects output similar to the Acrobat Distiller "Print Optimized" setting.
  • /prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting.