Skip to content

Instantly share code, notes, and snippets.

View kgorman's full-sized avatar

Kenny Gorman kgorman

View GitHub Profile
{"exportVersion":8,"dashboards":{"dashboard-1":{"title":"Movement","layout":[{"w":2,"h":2,"x":0,"y":0,"i":"item-1"},{"w":3,"h":2,"x":2,"y":0,"i":"item-2"}],"description":"Shows sensor movement","embedding":{},"filters":[]}},"items":{"item-1":{"title":"","description":"","dashboardId":"dashboard-1","dataSourceId":"data-source-1","iconValue":"gauge","itemType":"chart","filters":[],"missedFields":[],"lookupFields":[],"convertedFields":[],"calculatedFields":[],"channels":{"value":{"field":"acceleration","type":"quantitative","inferredType":"Number","channelType":"aggregation","aggregate":"sum"}},"reductions":{},"customisations":{"options":{"valueLabel":{"enabled":true,"value":null}},"axes":{"value":{"scaleMax":{"enabled":true,"value":"2500"},"scaleMin":{"enabled":true,"value":"1"}}},"channels":{"value":{"numberFormatting":{"enabled":true,"value":"Custom"},"numberDecimals":{"enabled":true,"value":"2"}}},"conditionalFormatting":[]},"chartType":"Gauge","meta":{},"sample":false,"query":null,"queryId":null,"interactiv
@kgorman
kgorman / README.md
Created January 24, 2023 21:06 — forked from magnetikonline/README.md
Python - comparing JSON data structures.

Python - comparing JSON data structures

A function compare_json_data(source_data_a,source_data_b), accepting structures populated with data loaded from json.load() and comparing for equality.

Example

$ ./compare.py 
Compare JSON result is: True
{"userid": 100, "theamount": 14000, "ending_ts": 1618848883}
{"userid": 200, "theamount": 23300, "ending_ts": 1618848883}
SELECT
userid,
SUM(amount) AS theamount,
tumble_end(timestamp, interval '1' hour) AS ending_ts
FROM mystream
GROUP BY userid, tumble(timestamp, interval '1' hour)
{"userid": 100, "amount": 10000, "timestamp": 1618852483}
{"userid": 200, "amount": 23000, "timestamp": 1618852483}
{"userid": 100, "amount": 4000, "timestamp": 1618848883}
{"userid": 200, "amount": 300, "timestamp": 1618848883}
// hello world
function HELLOWORLD() {
return "Hello World";
}
HELLOWORLD();
@kgorman
kgorman / sample4.sql
Last active October 25, 2019 16:26
sample4.sql
-- return aggregation of total payments
-- over a 1 hour tumbling window
SELECT SUM(CAST(amount AS numeric)) AS payment_volume,
CAST(TUMBLE_END(eventTimestamp, interval '1' hour) AS varchar) AS ts
FROM payments
GROUP BY TUMBLE(eventTimestamp, interval '1' hour);
@kgorman
kgorman / sample3.sql
Created October 25, 2019 15:39
sample3.sql
-- eventTimestamp is the Kafka timestamp
-- as unix timestamp. Magically added to every schema.
SELECT max(eventTimestamp) FROM solar_inputs;
-- make it human readable
SELECT CAST(max(eventTimestamp) AS varchar) as TS FROM solar_inputs;
-- dete math with interval
SELECT * FROM payments
WHERE eventTimestamp > CURRENT_TIMESTAMP-interval '10' second;
@kgorman
kgorman / sample2.sql
Created October 25, 2019 15:00
sample2.sql
-- detect multiple auths in a short window and
-- send to lock account topic/microservice
SELECT card,
MAX(amount) as theamount,
TUMBLE_END(eventTimestamp, interval '5' minute) as ts
FROM payments
WHERE lat IS NOT NULL
AND lon IS NOT NULL
GROUP BY card, TUMBLE(eventTimestamp, interval '5' minute)
HAVING COUNT(*) > 4 -- >4==fraud
@kgorman
kgorman / sample.sql
Created October 25, 2019 14:52
sample sql
-- new to my airspace
SELECT icao, pings FROM (
SELECT icao, speed,
COUNT(*) OVER (PARTITION BY icao ORDER BY eventTimestamp RANGE BETWEEN INTERVAL '60' SECOND PRECEDING AND CURRENT ROW) AS pings
FROM airplanes
) WHERE pings < 5
AND icao like 'A%'