Skip to content

Instantly share code, notes, and snippets.

@mjumbewu
mjumbewu / gatekeeper_logs.csv
Last active July 8, 2016 23:23
Simulating traffic against the AIS API
We can't make this file beautiful and searchable because it's too large.
ID,Class,Created,Endpoint ID,Key ID,Method,Path,Query,Response time,Response code,Response bytes,Test passed,Creator,Validation errors,Record title,Record url
42929373,Gatekeeper\Transactions\Transaction,1467057598,31,,GET,/account/406149600,format=json,846,200,2145,,,,,
42929372,Gatekeeper\Transactions\Transaction,1467057597,31,,GET,/account/871051400,format=json,892,200,2168,,,,,
42929370,Gatekeeper\Transactions\Transaction,1467057597,31,,GET,/account/022120300,format=json,839,200,2184,,,,,
42929369,Gatekeeper\Transactions\Transaction,1467057597,31,,GET,/address/2534%20HOLBROOK/,format=json,125,200,940,,,,,
42929368,Gatekeeper\Transactions\Transaction,1467057596,31,,GET,/address/1636%20SOUTH%2058TH%20STREET/,format=json,222,200,955,,,,,
42929366,Gatekeeper\Transactions\Transaction,1467057595,31,,GET,/address/1456%20N%20NEWKIRK%20STREET/,format=json,164,200,938,,,,,
42929365,Gatekeeper\Transactions\Transaction,1467057593,31,,GET,/address/4728%20TORRESDALE%20AVE/,format=json,128,200,55,,,,,
42929364,Gatekeepe
rejected = lambda r: r.action == 'Reject'
approved = lambda r: r.action == 'Approve'
expensive = lambda r: approved(r) and r.data['amount'] >= 500
workflow(
roles=[
'Employee',
'Supervisor',
'CFO',
'Travel Reviewer' ],
@mjumbewu
mjumbewu / loadtest.py
Last active October 9, 2016 00:58
Simple load tester that continuously sends GET requests to a list of URLs for a given duration of time. Requires python libraries click and requests.
#!/usr/bin/env python
from __future__ import print_function, division
import click
import csv
from datetime import timedelta
from itertools import cycle
from queue import Queue
import requests
@mjumbewu
mjumbewu / https_server.py
Created October 12, 2016 17:04
An extension to Python3's http.server module that allows creation of HTTPS servers. Inspired by @dergachev's even simpler https://gist.github.com/dergachev/7028596.
"""
An extension to Python3's http.server module that allows creation of HTTPS
servers. Inspired by @dergachev's https://gist.github.com/dergachev/7028596.
You can either use a separate certificate and key file:
python3 https_server.py -c server.crt -k server.key
Or generate a PEM file and use it as the certificate:
@mjumbewu
mjumbewu / python_distribution_resources.md
Last active November 2, 2016 17:22
Setup.py Documentation and Resources

Resources for Distributing Python Tools

When trying to figure out how to structure your Python tool for distribution, it can be difficult to get started. This represents a set of writings that I stumbled across, or that others have pointed me to, that I think would use as chapters in a setup.py book.

Preface

@mjumbewu
mjumbewu / ro_user.sql
Last active July 25, 2018 16:17
Create a user with read-only access to a PostgreSQL schema
-- 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;
@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.
@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
"""
{# template.html #}
<html>
<ul>
{{#each elems}}
{{>childelem}}
{{/each}}
</ul>
</html>
{# childelem.html #}
@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.