Skip to content

Instantly share code, notes, and snippets.

View dschep's full-sized avatar

Daniel Schep dschep

View GitHub Profile
@dschep
dschep / ST_TileEnvelope.sql
Last active May 23, 2025 09:14
ST_TileEnvelope backport
-- ported from https://github.com/pramsey/minimal-mvt/blob/58f3e695a305f42024dcf0ba395590bf39b0b573/minimal-mvt.py#L63-L81
CREATE OR REPLACE FUNCTION ST_TileEnvelope(tileZoom integer, tileX integer, tileY integer) RETURNS geometry AS $$
-- Width of world in EPSG:3857
DECLARE worldMercMax float = 20037508.3427892;
DECLARE worldMercMin float = -1 * worldMercMax;
DECLARE worldMercSize float = worldMercMax - worldMercMin;
-- Width in tiles
DECLARE worldTileSize float = power(2, tileZoom);
-- Tile width in EPSG:3857
DECLARE tileMercSize float = worldMercSize / worldTileSize;
@dschep
dschep / partially.py
Created October 1, 2020 12:51
A decorator version of functools.partial
def partially(*args, **kwargs):
"""
A decorator version of functools.partial
eg, this:
def _foo(x, y):
pass
foo = partial(_foo, 1)
is the same as:
@partially(1)
import { useState } from "react";
const useLocalStorageState = (storageKey, defaultValue) => {
const [value, setValue] = useState(
JSON.parse(localStorage.getItem(storageKey) || "null") || defaultValue
);
const wrappedSetValue = (newValue) => {
localStorage.setItem(storageKey, JSON.stringify(newValue));
setValue(newValue);
@dschep
dschep / metro.svg
Created January 23, 2020 00:42
Metro SVG from DC Metro Pro
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dschep
dschep / top9.py
Last active January 1, 2022 03:16
Instagram Top 9 - example output: https://www.instagram.com/p/B6vVp93Bb5F/
"""
An Instagram Top 9 generator that doesn't require connecting your account
to an untrustworthy 3rd party Instagram app.
Install the requirements with `pip3 install igramscraper Pillow click`
then run `python3 top9.py`
When done, you will have a YOURUSERNAME-top9.jpg in your working directory.
"""
from datetime import datetime
{
"features": [
{
"geometry": {
"coordinates": [
[
[
-76.99545991625094,
38.8494249445368
],
@dschep
dschep / bookmarklet.js
Last active March 3, 2020 14:55
Restore AWS shortcuts
javascript:(() => {
const newSc = prompt('enter shortcuts to restore');
/* Parse cookies into a map */
const cookies = new Map(document.cookie.split(/\s*;\s*/g).map(kv => kv.split('=')));
/* decode and parse the noflush_awscnm cookie */
const noflush_awscnm = JSON.parse(decodeURIComponent(cookies.get('noflush_awscnm')));
/* set shortcuts to those input by user */
noflush_awscnm.sc = newSc.split(',');
/* set the noflush_awscnm cookie (stringified & encoded) */
document.cookie = `noflush_awscnm=${encodeURIComponent(JSON.stringify(noflush_awscnm))}`;
@dschep
dschep / bookmarklet.js
Last active November 28, 2018 22:28
Get list of current AWS shortcuts
javascript:(() => {
/* Parse cookies into a map */
const cookies = new Map(document.cookie.split(/\s*;\s*/g).map(kv => kv.split('=')));
/* decode and parse the noflush_awscnm cookie */
const noflush_awscnm = JSON.parse(decodeURIComponent(cookies.get('noflush_awscnm')));
/* display the comma delimited shortcuts to user */
alert(`current shortcuts: ${noflush_awscnm.sc.join(',')}`);
})()
#!/usr/bin/env python
from requests_html import HTMLSession
session = HTMLSession()
resp = session.get('https://mailchi.mp/badcee76d7db/groupcamping?e=f74653273d')
groups = resp.html.find('#docs-internal-guid-242d83ee-6477-f6f4-5448-18ced87471f3', first=True).text.split('\n')
sites = resp.html.find('#docs-internal-guid-349ccfaa-6479-e25f-134f-289c9f089e3a', first=True).text.split('\n')
for group, site in zip(groups, sites):
print(f'{group}: {site}')
@dschep
dschep / JMSEPath-GBFS2GeoJSON.md
Last active June 12, 2019 18:03
JMSEPath Expressions to turn GBFS into GeoJSON

GBFS Bikes to GeoJSON

This creates a feature collection from the bikes endpoint of a GBFS service, such as JUMP DC's feed: https://dc.jumpmobility.com/opendata/free_bike_status.json

{type: `FeatureCollection`, features: data.bikes[*].{id: bike_id, geometry: {type: `Point`, coordinates: [lon, lat]}, properties: @}}

Example

GBFS Input:

{