Skip to content

Instantly share code, notes, and snippets.

@joshbrooks
joshbrooks / estrada-reporting-output.md
Last active January 10, 2020 14:06
A SQL query to generate a table

Inputs

Takes 3 tables. One is a list of attr One is a list of road_code One is a list of surveys

Expected output:

@joshbrooks
joshbrooks / chart_lister.py
Created May 23, 2019 05:26
List all Superset charts for iframe inclusion
# parser.py
# Requires "beautifulsoup4", pip install it
from bs4 import BeautifulSoup
import urllib.request
class SupersetRefPuller:
def __init__(self, url="https://superset-myeqip.catalpa.build/chart/list/"):
self.url = url
from decimal import Decimal

master = [{'name': 'Transport and storage', 'code': 210, 'pretty': '1.51B', 'value': 1506413922.22},
          {'name': 'Energy generation and supply', 'code': 230, 'pretty': '1.38B', 'value': 1381037466.9900002},
          {'name': 'Agriculture', 'code': 311, 'pretty': '873.91M', 'value': 873910810.5349958},
          {'name': 'Other multisector', 'code': 430, 'pretty': '775.72M', 'value': 775723989.434992},
          {'name': 'Government and civil society, general', 'code': 151, 'pretty': '562.41M',
           'value': 562410511.788092},
          {'name': 'Water and sanitation', 'code': 140, 'pretty': '541.16M', 'value': 541161168.5014064},

Openly Dashboard Optimisation

Beginning

Brief was to “make sure that all values displayed are consistent”. What's going on in this page (particularly the SQL and subsequent query hacking?)

Django Debug Toolbar (DJDT)

Setting up is fairly straightforward

@joshbrooks
joshbrooks / .gitignore
Last active April 26, 2017 07:22 — forked from octocat/.gitignore
Some common .gitignore configurations
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@joshbrooks
joshbrooks / formhub_update.mongo
Created October 11, 2016 07:27
updating Formhub instances
db.instances.update(
{"formhub/uuid" : "faec0c656d1e4665b92b9f3c63eb4913"},
{ $set: {
_xform_id_string : "2_Vizita_No_Atividade_Mentor_Nian",
_userform_id: "edu_2_Vizita_No_Atividade_Mentor_Nian",
"formhub/uuid": "72b5006f97234e029942358be11969c6"
}},
{ multi: true } )
@joshbrooks
joshbrooks / geometrysplits.sql
Created May 12, 2013 13:10
PostGIS functions to split polygons along their longest length. Uses a count of the number of interior polygons as a measuer of complexity. Change "WHERE st_numinteriorrings(geom)" to area or another geom function if necessary
--CREATE SCHEMA sandbox;
CREATE TABLE IF NOT EXISTS sandbox.test(id serial, geom geometry);
TRUNCATE sandbox.test;
CREATE OR REPLACE FUNCTION sandbox.split_geometry(ageom geometry, OUT the_geom geometry)
RETURNS SETOF geometry AS
$$
-- If polygon bbox is longer in the East-West direction, split by a North-South
-- line at the center of the polygon