Skip to content

Instantly share code, notes, and snippets.

@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
View django urlpattern list .py
# 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.
View timeout.js
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
View xpath.md
@mjumbewu
mjumbewu / auto_water.py
Last active September 17, 2019 14:55 — forked from benrules2/auto_water.py
View 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
View dump-csv
#!/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 March 25, 2021 18:17
PostGIS function to generate a grid of hexagonal cells in a PostgreSQL database
View 1-hexgrid_illustration.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View templates.hbs
{# 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.
View admin_decorators.py
"""
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.
View bootstrap_tables.py
"""
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.
@mjumbewu
mjumbewu / ro_user.sql
Last active July 25, 2018 16:17
Create a user with read-only access to a PostgreSQL schema
View ro_user.sql
-- Create the user. You only have to run this once.
CREATE ROLE joebloggs WITH LOGIN PASSWORD '...';
-- Once the user is created, give access to the tables.
-- Note, if a table is dropped and recreated, you will
-- have to re-run the GRANT SELECT command.
GRANT USAGE ON SCHEMA my_schema TO joebloggs;
GRANT SELECT ON ALL TABLES IN SCHEMA my_schema TO joebloggs;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA my_schema TO joebloggs;