Skip to content

Instantly share code, notes, and snippets.

@Nxtra
Nxtra / template.yaml
Created Sep 24, 2019
Integrating AWS SAM with OpenAPI
View template.yaml
AWSTemplateFormatVersion : "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: Conference API Service
Globals:
Api:
Cors:
AllowMethods: "'*'"
AllowHeaders: "'Content-Type'"
AllowOrigin: "'*'"
View join-api.yml
---
openapi: 3.0.0
info:
description: API for the Ordina conference event
version: '1'
title: Conference-API
servers:
- url: "https://your-conference-domain.com/api/"
description: 'Base URL for the API'
paths:
@Nxtra
Nxtra / delete-all-models.py
Created Jan 17, 2020
Delete all sagemaker models
View delete-all-models.py
import boto3
from pprint import pprint
client = boto3.client('sagemaker')
def main():
model_names = []
for key in paginate(client.list_models):
@Nxtra
Nxtra / oauth2-cognito-foobar.sh
Created Jul 17, 2020
Code that is used in the example given by Foobar's "OAUTH 2.0 EXPLAINED IN SIMPLE WORDS (Amazon Cognito)": https://www.youtube.com/watch?v=7kwqPoeEt1c
View oauth2-cognito-foobar.sh
APP_ID=2kou24pdi9pagm6bawd3jb0jrd
APP_SECRET=be9noij0kc98u80asfnomjnm7ppk1pm240vvae
URL="my-test-poo.auth.eu-west-1.amazoncognito.com"
BASIC=$(echo -n $APP_ID:$APP_SECRET | base64)
AUTHENTICATE="Basic $BASIC"
echo "https://$URL/oauth2/authorize?response_type=code&client_id=$APP_ID&state=12345&redirect_uri=http://localhost&scope=aws.cognito.signin.user.admin%20email%20openid%20profile&" | pbcopy
https://my-test-pool.auth.eu-west-1.amazoncognito.com/oauth2/authorize?
response_type=code
View reference-data.sql
CREATE OR REPLACE PUMP "YOUR_IN_APPLICATION_STREAM" AS
INSERT INTO "YOUR_IN_APPLICATION_PUMP" ("uniqueId", "currentSpeed", ..., "location")
SELECT STREAM
"sdi"."uniqueId",
"sdi"."currentSpeed",
...,
"ml"."locatie",
FROM "SPEED_DIFF_INDICATOR_SQL_STREAM" AS "sdi" LEFT JOIN "measurementLocations" as "ml"
ON "sdi"."uniqueId" = "ml"."id";
View lag.sql
CREATE OR REPLACE PUMP "SPEED_CHANGE_PUMP" AS
INSERT INTO "SPEED_CHANGE_SQL_STREAM"
SELECT STREAM "s"."uniqueId",
LAG("s"."speed", 1, "s"."speed") OVER CURRENT_WINDOW AS "previousSpeed",
"s"."speed" AS "currentSpeed"
FROM "SPEED_SQL_STREAM" AS "s"
WINDOW CURRENT_WINDOW AS (PARTITION BY "s"."uniqueId" ROWS 3 PRECEDING);
View window.sql
CREATE OR REPLACE PUMP "STREAM_PUMP_SPEED" AS
INSERT INTO "SPEED_SQL_STREAM"
SELECT STREAM
"uniqueId",
AVG("speed") over W0,
AVG("speed") over W2,
AVG("speed") over W10
FROM "INCOMING_STREAM"
WINDOW
W0 AS ( PARTITION BY "uniqueId"
View handler.python
def handle(event, context):
output = []
for record in event['records']:
payload = base64.b64decode(record['data'])
result = dropped_or_okay(payload)
if result == 'Ok':
payload = preprocess_payload(payload)
View create-stream-pump.sql
CREATE OR REPLACE STREAM "INCOMING_STREAM" (
"uniqueId" INTEGER,
"speed" INTEGER,
"bezettingsgraad" INTEGER,
"recordTimestamp" TIMESTAMP);
CREATE OR REPLACE PUMP "INCOMING_STREAM_PUMP" AS
INSERT INTO "INCOMING_STREAM"
SELECT STREAM
"unieke_id",
View event.JSON
{
"beschrijvende_id": "H101L20",
"unieke_id": "3159",
"lve_nr": "18",
"tijd_waarneming": "2020-04-06T17:51:00+01:00",
"tijd_laatst_gewijzigd": "2020-04-06T17:52:20+01:00",
"actueel_publicatie": "1",
"beschikbaar": "1",
"defect": "0",
"geldig": "0",