Skip to content

Instantly share code, notes, and snippets.

View jongio's full-sized avatar

Jon Gallant jongio

View GitHub Profile
@jongio
jongio / azure-iot-hub-device-twin-rest-apis-postman-newman.js
Last active November 5, 2021 08:50
Azure IoT Hub SAS Token JavaScript CryptoJS
// See this doc for details: https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-security
var resourceUri = encodeURIComponent(postman.getGlobalVariable("hubName") + '.azure-devices.net'); // The resource uri
var expiry = Math.ceil((Date.now() / 1000) + postman.getGlobalVariable("expiresInMins") * 60); // Expire the token 60 minutes from now
var uriExpiry = resourceUri + '\n' + expiry; // this is the string format to gen signature from
var decodedKey = CryptoJS.enc.Base64.parse(postman.getGlobalVariable("signingKey")); // The SHA256 key is the Base64 decoded version of the IoT Hub key
var signature = CryptoJS.HmacSHA256(uriExpiry, decodedKey); // The signature generated from the decodedKey
var encodedUri = encodeURIComponent(CryptoJS.enc.Base64.stringify(signature)); // The url encoded version of the Base64 signature
// Construct authorization string (shared access signature)
var token = "SharedAccessSignature sr=" + resourceUri + "&sig=" + encodedUri + "&se=" + expiry;
@jongio
jongio / pbie.cmd
Last active July 24, 2018 13:49
Power BI Embedded via Azure CLI Command Line Script
az group deployment create -g %1 --template-uri https://gist.githubusercontent.com/jongio/b55a0f3e8433a0484a6d07f2c7a724ac/raw/789df146e23c7a9c6e56cbec6335991491510b5a/pbiearm.json --parameters "{\"name\": {\"value\": \"%2\"}, \"location\": {\"value\": \"%3\"}}" --debug
@jongio
jongio / pbiearm.json
Created January 9, 2017 22:45
Power BI Embedded ARM Template
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"defaultValue": "jongpbie-test1",
"type": "String"
},
"location": {
"defaultValue": "westus",
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var Protocol = require('azure-iot-device-amqp').Amqp;
// Uncomment one of these transports and then change it in fromConnectionString to test other transports
// var Protocol = require('azure-iot-device-amqp').AmqpWs;
// var Protocol = require('azure-iot-device-http').Http;
// var Protocol = require('azure-iot-device-mqtt').Mqtt;
@jongio
jongio / visual.less
Created December 13, 2016 23:50
Code for svg/png in Power BI custom visual
#iothub {
display:inline-block;
*display:inline;
width: 512px;
height: 512px;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAMAAADDpiTIAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQBt1gBxxgRx0ghx1gxxzgh1yhB1xhB12hB5yhR5whh52hx9vhh9yiCBtiB92iiFsiCFziyFriiF3jSJqjiNoTCJ3jCN0jyRnUCRnTiNykCRpTiN3kSVmTiR0kiVkTyR3kCR1kCR4lCZjUCV1lWdiUiV4kiZ0kiZ1lmdpV2hhWGhfVCZ4lCd2mWleWGhum2qdVmh2lmh5nGubWGl3mGl5nmyaX2yZWmq5oW2YXmymWmu3om6WYG2hXmyvnGu6nGy3pG+VXmy6pXCUHm24n226pnGSH264oW60qHGRIW66qXKQIW+5o2+0om+4q7OPI2+7o3C5pXC0rLSNJXC7pXG5rrWMLrWOL7WPJ3K6p3K7r7aRMLaTMLaUKXO6qXO8sbeWcreXbLS4q7S7q7S8sreZbbW7s7ibbbW8s7icdLiecrikdLmfb7a9r7e8tbmhdrmjcbe9trqkdrqmd7qnc7i9s7m9uLupeLuqubustbq9tbq+ubyuuryvt7u+uryxu72zuby+u720vL22u72+u72//b63vb65vr67vb6//r/8v//+v///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
var css = document.createElement('span');
css.id = "iothub";
this.target.appendChild(css);
#iothub {
display:inline-block;
*display:inline;
width: 512px;
height: 512px;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAMAAADDpiTIAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQBt1gBxxgRx0ghx1gxxzgh1yhB1xhB12hB5yhR5whh52hx9vhh9yiCBtiB92iiFsiCFziyFriiF3jSJqjiNoTCJ3jCN0jyRnUCRnTiNykCRpTiN3kSVmTiR0kiVkTyR3kCR1kCR4lCZjUCV1lWdiUiV4kiZ0kiZ1lmdpV2hhWGhfVCZ4lCd2mWleWGhum2qdVmh2lmh5nGubWGl3mGl5nmyaX2yZWmq5oW2YXmymWmu3om6WYG2hXmyvnGu6nGy3pG+VXmy6pXCUHm24n226pnGSH264oW60qHGRIW66qXKQIW+5o2+0om+4q7OPI2+7o3C5pXC0rLSNJXC7pXG5rrWMLrWOL7WPJ3K6p3K7r7aRMLaTMLaUKXO6qXO8sbeWcreXbLS4q7S7q7S8sreZbbW7s7ibbbW8s7icdLiecrikdLmfb7a9r7e8tbmhdrmjcbe9trqkdrqmd7qnc7i9s7m9uLupeLuqubustbq9tbq+ubyuuryvt7u+uryxu72zuby+u720vL22u72+u72//b63vb65vr67vb6//r/8v//+v///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
var svg = document.createElement(null);
svg.innerHTML = this.iotHubSvg;
this.target.appendChild(svg);
private iotHubSvg = '<svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="-783 985 32 32"><style>.st0{fill:#B8D432;} .st1{fill:#0072C6;} .st2{fill:#006DD6;}</style><path class="st0" d="M-763.288 1000.266l-7.074-10.062 1.31-.92 7.073 10.062z"/><path class="st0" d="M-757.03 1011.085l-6.26-10.936 1.388-.796 6.26 10.936z"/><path class="st0" d="M-777.836 1001.936l-.132-1.595 15.248-1.265.132 1.595z"/><path class="st0" d="M-767.31 1009.197l-1.37-.826 5.368-8.907 1.37.826z"/><path class="st1" d="M-751.5 985h-8.1c-.3 0-.5.2-.5.6v2.9c0 .3.2.5.5.5h4.6v4.5c0 .3.2.5.6.5h2.9c.3 0 .5-.2.5-.5v-8c0-.3-.2-.5-.5-.5zM-782.5 1016.9h8.1c.3 0 .5-.2.5-.6v-2.9c0-.3-.2-.5-.5-.5h-4.6v-4.5c0-.3-.2-.5-.6-.5h-2.9c-.3 0-.5.2-.5.5v8c0 .3.2.5.5.5z"/><circle class="st2" cx="-769.6" cy="989.9" r="3.1"/><circle class="st2" cx="-762.5" cy="999.9" r="3.7"/><circle class="st2" cx="-756.3" cy="1010.9" r="2.9"/><circle class="st2" cx="-767.8" cy="1008.9" r="2.5"/><circle class="st2" cx="-777.9" cy="1001.3" r="2.5"
// Originally from: https://community.powerbi.com/t5/Community-Blog/Aggregating-Duration-Time/ba-p/22486
Duration =
// Duration formatting
// * @konstatinos 1/25/2016
// * Given a number of seconds, returns a format of "hh:mm:ss"
//
// We start with a duration in number of seconds
VAR Duration = [Change this value to the name of your column that contains your seconds value]
// There are 3,600 seconds in an hour
VAR Hours =