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
# Ensure we have the latest pip and pipenv | |
pip3 install --upgrade pip pipenv | |
# Setup new Python 3.8 project | |
pipenv --python 3.8 | |
# Install aws-lambda-powertools | |
pipenv install boto3 aws-lambda-powertools | |
# Install dev dependencies | |
pipenv install black pytest --dev --pre |
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 dataclasses import dataclass, fields as datafields | |
from ujson import dumps, loads | |
# Note: ujson seamlessly serializes dataclasses, unlike stdlib's json | |
@dataclass | |
class Point: | |
x: float | |
y: float | |
# Shallow dataclass can be rebuilt from dict/json: |
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
""" | |
* requires usaddress https://github.com/datamade/usaddress | |
* check out the website! https://parserator.datamade.us/usaddress | |
The usaddress package is pretty great for normalizing inconsistent address data, | |
especially when if you have a lot to process and can't rely on using a geocoding api. | |
The results are really granular, probably moreso than you'll need, and definitely | |
more than most CRM systems if integrating these addresses is your goal. | |
This is just a simple wrapper around the usaddress.tag() function that I feel will |
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
-- Function: makegrid_epsg3857(text, text, text, numeric) | |
-- DROP FUNCTION makegrid_epsg3857(text, text, text, numeric); | |
CREATE OR REPLACE FUNCTION makegrid_epsg3857(schemaname text, boundingbox text, gridtable text, halfwidth numeric) | |
RETURNS text AS | |
$BODY$ | |
DECLARE | |
tbl_cnt int; | |
XMIN numeric; |
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
CREATE FUNCTION batch_at_will() RETURNS INTEGER LANGUAGE plpgsql AS $$ | |
DECLARE batched_count INTEGER = 1; | |
BEGIN | |
WITH selected_users AS ( | |
SELECT id | |
FROM users | |
WHERE role = 'moderator' | |
AND registration_date < CURRENT_DATE - INTERVAL '4' YEAR | |
LIMIT 1000 | |
FOR UPDATE NOWAIT |
Someone asked how to get the latlong from a specific road near a town on OpenStreetMap.
If you need to do it only once (e.g., you're about to go on a trip, and your GPS cannot find your destination city, but allows you to enter GPS coordinates), you can use Nominatim, OpenStreetMap's geocoding interface.
If you need to do it multiple times, in a programmatic manner, there are at least two ways to do that.
Note: I worked with OSM data a couple of years ago, but I don't have an OSM database on my local laptop right now, so some instructions will be a bit fuzzy. I do apologize in advance.
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
CREATE TRIGGER person_notify AFTER INSERT OR UPDATE OR DELETE ON income | |
FOR EACH ROW EXECUTE PROCEDURE notify_trigger( | |
'id', | |
'email', | |
'username' | |
); | |
CREATE TRIGGER income_notify AFTER INSERT OR UPDATE OR DELETE ON income | |
FOR EACH ROW EXECUTE PROCEDURE notify_trigger( | |
'id', |
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 | |
# | |
# Install Postgres 9.1, PostGIS and create PostGIS template on a clean Ubuntu 11.10 Oneiric Ocelot box | |
# http://wildfish.com | |
# add the ubuntu gis ppa | |
sudo apt-get -y install python-software-properties | |
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable | |
sudo apt-get update |
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
-- | |
-- Create a valid GEOMETRY in 4326 from a lat/lng pair | |
-- | |
-- @param lat A numeric latitude value. | |
-- | |
-- @param lng A numeric longitude value. | |
-- | |
-- | |
CREATE OR REPLACE FUNCTION CDB_LatLng (lat NUMERIC, lng NUMERIC) RETURNS geometry as $$ |
NewerOlder