Skip to content

Instantly share code, notes, and snippets.

View jwilson8767's full-sized avatar
🐟
Feeling focused

Jay Cary jwilson8767

🐟
Feeling focused
View GitHub Profile
import boto3
def ddb_delete_all_items(table_id, partition_key, sort_key=None):
"""
Bulk deletion of all items in a DynamoDB Table.
See also:
[AWS REST API doc](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html)
[boto3 doc](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#DynamoDB.Client.batch_write_item)
@jwilson8767
jwilson8767 / rounding_utils.js
Created April 28, 2020 21:43
More javascript rounding options!
/*
I had trouble finding simple methods for rounding modes like half-even and
half-away-from-zero in Javascript, so here's what I came up with! Enjoy!
MIT licensed
*/
/**
* Applies half-even rounding to the given number of significant figures. Supports n as a single value or series.
@jwilson8767
jwilson8767 / python-and-gis-rources.md
Last active October 1, 2019 16:48
Python and GIS resources

Python and GIS Resources

This is an entrypoint into the world of GIS using Python. It's not everything you'll need to know, but it should help you get oriented and serve as a reference in the future.

A couple tools I recommend you setup right from the start are Conda:

  1. The Conda package manager is a quick way to get a working python environment and add bells and whistles as needed.
  2. Once you have conda, run conda install -c conda-forge jupyter pandas geopandas using your Conda Prompt to get a bunch of the packages I expect you'll need right from the start. The -c conda-forge specifies that conda should try to lookup things in the "Conda Forge" package repository, which is how many of the open source python GIS tools are distributed. Jupyter is an interactive python programming tool that makes it easy to experiment and make mistakes. Pandas and GeoPandas are covered more below.
  3. Now that you have Jupyter, you can run jupyter notebook in your Conda Prompt
@jwilson8767
jwilson8767 / glob_apply.py
Last active August 18, 2019 02:20
Python wildcard apply / glob apply
# MIT LICENSED
# Author: jwilson8767
import collections
def glob_apply(obj, paths, fn: callable, **kwargs) -> None:
"""
Iterates a deeply nested structure using dot-notation wildcard paths.
:param obj: The List/Sequence or Dict/Mapping to iterate
def beep():
# try to use windows sound to beep
try:
import winsound
winsound.PlaySound('SystemQuestion', winsound.SND_ALIAS)
except ImportError:
pass
# usually works on unix systems
@jwilson8767
jwilson8767 / sjoin.py
Created February 19, 2019 19:05
Geopandas concurrent sjoin
from concurrent.futures import as_completed, ProcessPoolExecutor
import geopandas as gpd
import pandas as pd
import numpy as np
from collections.abc import Sequence
from shapely import prepared
def sjoin(left_df, right_df, op='intersects', how='inner', lsuffix='left', rsuffix='right', fail_crs_mismatch: bool = True, fail_missing_geometries: bool = False) -> gpd.GeoDataFrame:
"""Spatial join of two GeoDataFrames. GeoPandas sjoin with concurrency (split naively using df slicing).
@jwilson8767
jwilson8767 / install_WSL_docker.sh
Last active May 14, 2020 17:17
Docker Toolbox for Windows and Windows Subsystem for Linux (aka Bash on Windows)
#
# This script installs and configures WSL to work with Docker Toolbox for Windows.
# 1. Install WSL (check out [bowinstaller](https://github.com/xezpeleta/bowinstaller) for programmatic installation.
# 2. Run the contents of this script in Bash. (copy and paste works fine, no need to save)
#
sudo -sEH << 'EOM'
# Install the docker client and docker-compose
apt-get update && apt-get install -y curl ca-certificates
curl -sSL https://get.docker.com/ | sh
curl -L "https://github.com/docker/compose/releases/download/1.11.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
@jwilson8767
jwilson8767 / es6-element-ready.js
Last active April 22, 2024 20:28
Wait for an element to exist. ES6, Promise, MutationObserver
// MIT Licensed
// Author: jwilson8767
/**
* Waits for an element satisfying selector to exist, then resolves promise with the element.
* Useful for resolving race conditions.
*
* @param selector
* @returns {Promise}
*/