Skip to content

Instantly share code, notes, and snippets.

@mjumbewu
mjumbewu / leaflet-smoothrender.js
Last active October 22, 2024 15:29
A Leaflet renderer that will reproject vector layers at each step of an animated transition. This renderer is best when you have relatively few features.
const SmoothRenderer = L.SVG.extend({
// Override the default _onZoom function, which simply scales the lower
// resolution shapes. Instead, we want to reproject the shapes at each new
// zoom level, as is done by default when zooming ends.
_onZoom: function () {
this._onZoomEnd();
this._update();
}
});
@mjumbewu
mjumbewu / django urlpattern list .py
Last active February 8, 2024 20:40 — forked from ashishtajane/django urlpattern list .py
Get all URL patterns in django
# Open django shell and do following.
from django.urls import get_resolver
def show_urls(urllist, depth=0):
for entry in urllist:
print(' ' * depth, entry.pattern)
if hasattr(entry, 'url_patterns'):
show_urls(entry.url_patterns, depth + 1)
@mjumbewu
mjumbewu / timeout.js
Created August 19, 2022 14:48
A simple JavaScript function to allow using setTimeout with async/await.
function timeout(duration) {
return new Promise((resolve) => {
setTimeout(resolve, duration);
});
}
/*
Example:
async function dostuff() {
@mjumbewu
mjumbewu / xpath.md
Last active February 24, 2020 01:16
SEPTA Key Trip Grid Parser
@mjumbewu
mjumbewu / auto_water.py
Last active September 17, 2019 14:55 — forked from benrules2/auto_water.py
import water
if __name__ == "__main__":
water.auto_water()
@mjumbewu
mjumbewu / dump-csv
Created July 24, 2018 19:05
Shell script to dump a CSV file from a database table
#!/bin/sh -e
table=$1
psql -U $DBUSER -h $DBHOST -p $DBPORT $DBNAME -c \
"COPY (SELECT * FROM $table) TO STDOUT WITH CSV HEADER"
@mjumbewu
mjumbewu / 1-hexgrid_illustration.svg
Last active October 27, 2024 07:01
PostGIS function to generate a grid of hexagonal cells in a PostgreSQL database
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{# template.html #}
<html>
<ul>
{{#each elems}}
{{>childelem}}
{{/each}}
</ul>
</html>
{# childelem.html #}
@mjumbewu
mjumbewu / admin_decorators.py
Last active February 21, 2018 21:38
Decorators for quickly setting up links to related model instances in the Django admin.
"""
Sometimes it can be useful to quickly navigate between objects.
This module defines two useful decorators:
* admin_link
* admin_changelist_link
Borrowed, with love, from:
https://medium.com/@hakibenita/things-you-must-know-about-django-admin-as-your-app-gets-bigger-6be0b0ee9614
"""
@mjumbewu
mjumbewu / bootstrap_tables.py
Last active August 24, 2017 13:34
A line-for-line copy of markdown.extensions.tables, except that the table element is created with a "table" class, so that it is properly styled by Bootstrap.
"""
Twitter Bootstrap Tables Extension for Python-Markdown
======================================================
A line-for-line copy of [`markdown.extensions.tables`](https://github.com/Python-Markdown/markdown/blob/2.6.9/markdown/extensions/tables.py),
except that the table element is created with a "table" class, so that it is
properly styled by bootstrap.
See <https://pythonhosted.org/Markdown/extensions/tables.html>
for documentation.