This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/python | |
# http://exploreflask.com/en/latest/views.html | |
# https://stackoverflow.com/questions/51691730/flask-middleware-for-specific-route | |
# https://dev.to/rhymes/logging-flask-requests-with-colors-and-structure--7g1 | |
import logging | |
from logging.handlers import RotatingFileHandler | |
from flask import Flask, request, jsonify | |
from time import strftime |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Code borrowed from https://subscription.packtpub.com/book/application_development/9781783984985/1/ch01lvl1sec18/creating-a-standalone-application | |
# and upgraded for QGIS 3.0 | |
import sys | |
from qgis.core import (QgsApplication, QgsFeature, QgsGeometry, | |
QgsProject, QgsVectorLayer) | |
from qgis.gui import QgsMapCanvas | |
from qgis.PyQt.QtCore import Qt | |
# Unused so commented | |
# from qgis.PyQt.QtGui import * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- convert a grid-reference E.g. SH123456 into a northing easting geometry for postgis with SRID=27700 (OSGB36) | |
-- standing on the shoulders of... | |
-- http://www.movable-type.co.uk/scripts/latlong-os-gridref.html | |
-- https://github.com/chrisveness/geodesy/blob/master/osgridref.js [MIT] | |
-- consider this MIT licensed also. | |
CREATE OR REPLACE FUNCTION get_geom_from_grid_ref(IN grid_ref character varying) | |
RETURNS public.geometry | |
LANGUAGE 'plpgsql' | |
AS $BODY$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# got a huge ammount of help from https://stackoverflow.com/questions/11550153/determine-position-of-number-in-a-grid-of-numbers-centered-around-0-and-increasi | |
def sequence(i): | |
n = 2 * i - 1 | |
return n * n | |
def layer(i): | |
return math.floor((math.sqrt(i) + 1) / 2) | |
def length(i): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int SpiralMemoryPartOne(int location) | |
{ | |
if (location <= 1) return 0; | |
var ring = 1; | |
var max = 9; | |
while (max < location) | |
{ | |
ring += 1; | |
max += (((ring + 1) * 2) - 2) * 4; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
objects_id_object_seq - sequence name | |
objects - table name | |
id_object - ID field name | |
seq - standard postfix | |
Doc for setval() and nextval(): https://www.postgresql.org/docs/current/functions-sequence.html | |
*/ | |
CREATE SEQUENCE IF NOT EXISTS objects_id_object_seq; -- IF NOT EXISTS is works only in Postgres 9.5+ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
exports.handler = (event, context, callback) => { | |
// Get request and request headers | |
const request = event.Records[0].cf.request; | |
const headers = request.headers; | |
// Configure authentication | |
const authUser = 'user'; | |
const authPass = 'pass'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from: | |
http://chase-seibert.github.io/blog/2014/01/12/python-unicode-console-output.html | |
Print to the console in Python without UnicodeEncodeErrors 12 Jan 2014 | |
I can't believe I just found out about this! If you use Python with unicode data, such as Django database records, you may have seen cases where you print a value to the console, and if you hit a record with an extended (non-ascii) character, your program crashes with the following: | |
Traceback (most recent call last): | |
File "foobar.py", line 792, in <module> | |
print value | |
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
apt-get install openjdk-8-jre | |
# PostgreSQL and PostGIS | |
apt-get install postgresql postgresql-contrib postgis postgresql-10-postgis-2.4 | |
# Create "geoserver" database | |
sudo -u postgres createuser -P geoserver | |
sudo -u postgres createdb -O geoserver geoserver | |
sudo -u postgres psql -c "CREATE EXTENSION postgis; CREATE EXTENSION postgis_topology;" geoserver |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# useful for platforms such as Cygwin that don't currently have GNU Parallel in their repo. | |
# prerequisite: make | |
( | |
wd=$(mktemp -d) | |
wget -nc -P $wd ftp://ftp.gnu.org/gnu/parallel/parallel-latest.tar.bz2 | |
cd $wd |