Skip to content

Instantly share code, notes, and snippets.

View devjourney's full-sized avatar

W. Kevin Hazzard devjourney

View GitHub Profile
@devjourney
devjourney / GetStationWeatherDataWithJmesPathQuery.js
Created September 2, 2018 16:35
A Node.js function to fetch weather station data then filter and shape it with JMESPath.
let documentClient = require('documentdb').DocumentClient;
let jmespath = require('jmespath');
let cosmos_uri = process.env["STATION_COSMOS_URI"];
let cosmos_key = process.env["STATION_COSMOS_READONLY_KEY"];
let databaseId = process.env["STATION_COSMOS_DATABASE_NAME"];
let collectionId = process.env["STATION_COSMOS_COLLECTION_NAME"];
let client = new documentClient(cosmos_uri, { 'masterKey': cosmos_key });
let collectionLink = "/dbs/" + databaseId + "/colls/" + collectionId + "/";
module.exports = function (context, req) {
@devjourney
devjourney / GetStationWeatherData.js
Last active September 2, 2018 16:35
A Node.js function to fetch weather station data.
let documentClient = require('documentdb').DocumentClient;
let cosmos_uri = process.env["STATION_COSMOS_URI"];
let cosmos_key = process.env["STATION_COSMOS_READONLY_KEY"];
let databaseId = process.env["STATION_COSMOS_DATABASE_NAME"];
let collectionId = process.env["STATION_COSMOS_COLLECTION_NAME"];
let client = new documentClient(cosmos_uri, { 'masterKey': cosmos_key });
let collectionLink = "/dbs/" + databaseId + "/colls/" + collectionId + "/";
module.exports = function (context, req) {
let filterQuery = `SELECT * FROM c WHERE c.State = "${req.params.state}"`;
@devjourney
devjourney / UpsertProcedureAndExecuteV1.js
Last active December 9, 2018 21:09
A Node.js app that creates a Cosmos DB stored procedure and executes it.
var CosmosClient = require('@azure/cosmos').CosmosClient;
var config = require('./config.js');
var client = new CosmosClient({
endpoint: config.connection.endpoint,
auth: { masterKey: config.connection.authKey }
});
async function upsertProcedureAndExecute(sprocDef, docToInsert) {
const { database } = await client.databases
.createIfNotExists({ id: config.names.database });
@devjourney
devjourney / CreateCosmosDbAuthTokenInPostman.js
Created August 31, 2018 23:58
Create an authorization token for CosmosDB in a Postman Pre-test Script
var now = new Date().toUTCString();
pm.environment.set("utcDate", now);
var verb = 'GET';
var resourceType = pm.variables.get("resourceType");
var resourceId = pm.variables.get("resourceId");
var text = (verb || "").toLowerCase() + "\n" + (resourceType || "").toLowerCase() + "\n" + (resourceId || "") + "\n" + now.toLowerCase() + "\n" + "" + "\n";
var key = CryptoJS.enc.Base64.parse(pm.variables.get("masterKey"));
var signature = CryptoJS.HmacSHA256(text, key).toString(CryptoJS.enc.Base64);
@devjourney
devjourney / flashingledswithbuttoncontrolleddelay.py
Last active December 8, 2019 04:36
Python script for Raspberry Pi to alternate flashing of two LEDs with two buttons for modifying the duration of the delays between alternations.
from gpiozero import LED, Button
from time import sleep
minimum = 0.0625
maximum = 1.00
increment = 0.0625
delay = minimum
def set_delay(offset):
global delay, minimum, maximum
@devjourney
devjourney / ILI9341_TFT_LCD_Simple_Counter.py
Last active January 7, 2024 01:23
CircuitPython ILI9341 TFT Showing Second Counter
import board
import time
import terminalio
import displayio
import digitalio
from adafruit_display_text import label
import adafruit_ili9341
# Release any resources currently in use for the displays
displayio.release_displays()