Skip to content

Instantly share code, notes, and snippets.

Avatar

W. Kevin Hazzard devjourney

View GitHub Profile
@devjourney
devjourney / flashingledswithbuttoncontrolleddelay.py
Last active Dec 8, 2019
Python script for Raspberry Pi to alternate flashing of two LEDs with two buttons for modifying the duration of the delays between alternations.
View flashingledswithbuttoncontrolleddelay.py
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 / UpsertProcedureAndExecuteV1.js
Last active Dec 9, 2018
A Node.js app that creates a Cosmos DB stored procedure and executes it.
View UpsertProcedureAndExecuteV1.js
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 / GetStationWeatherDataWithJmesPathQuery.js
Created Sep 2, 2018
A Node.js function to fetch weather station data then filter and shape it with JMESPath.
View GetStationWeatherDataWithJmesPathQuery.js
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 Sep 2, 2018
A Node.js function to fetch weather station data.
View GetStationWeatherData.js
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 / CreateCosmosDbAuthTokenInPostman.js
Created Aug 31, 2018
Create an authorization token for CosmosDB in a Postman Pre-test Script
View CreateCosmosDbAuthTokenInPostman.js
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);