Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Schep dschep

View GitHub Profile
@dschep
dschep / partially.py
Created Oct 1, 2020
A decorator version of functools.partial
View partially.py
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)
View useLocalStorageState.js
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 Jan 23, 2020
Metro SVG from DC Metro Pro
View metro.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View top9.py
"""
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
View data.json
{
"features": [
{
"geometry": {
"coordinates": [
[
[
-76.99545991625094,
38.8494249445368
],
@dschep
dschep / bookmarklet.js
Last active Mar 3, 2020
Restore AWS shortcuts
View bookmarklet.js
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 Nov 28, 2018
Get list of current AWS shortcuts
View bookmarklet.js
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(',')}`);
})()
View dirtfest-camping.py
#!/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 Jun 12, 2019
JMSEPath Expressions to turn GBFS into GeoJSON
View JMSEPath-GBFS2GeoJSON.md

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:

{
@dschep
dschep / nvim-terminal-edit.py
Last active Jan 9, 2018 — forked from tarruda/nvim-terminal-edit.py
Edit file in host Neovim instance from a :terminal buffer
View nvim-terminal-edit.py
#!/usr/bin/env python
"""Edit a file in the host nvim instance."""
import os
import sys
from neovim import attach
args = sys.argv[1:]
addr = os.environ.get("NVIM_LISTEN_ADDRESS", None)
You can’t perform that action at this time.