Skip to content

Instantly share code, notes, and snippets.

Avatar
🤙
https://mckelt.com

Chris McKelt chrismckelt

🤙
https://mckelt.com
View GitHub Profile
@chrismckelt
chrismckelt / ProductionIssueBugTemplate.txt
Last active Jun 7, 2021
Production Issue Bug Template
View ProductionIssueBugTemplate.txt
#### Issue Name
#### Priority high|medium|low
#### Issue Summary
- What? – What has happened with the application?
- How? – What did we click/do to produce the bug?
- Where? – Where exactly in the app did we find the bug? What is the webpage and/or server (environment)?
- Who? noticed the issue? staff ID or customer ID?
View Impersonation.cs
using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Security.Principal;
namespace ExampleNameSpace
{
public class Impersonation : IDisposable
{
@chrismckelt
chrismckelt / Get-AccessToken .ps1
Created Jun 24, 2020
PowerShell Get-AccessToken
View Get-AccessToken .ps1
function Get-AccessToken {
$context = Get-AzContext
$myprofile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($myprofile)
$token = $profileClient.AcquireAccessToken($context.Subscription.TenantId)
return $token.AccessToken
}
@chrismckelt
chrismckelt / configure-log-analytics.ps1
Created Jun 17, 2020
Turn on log analytics diagnostics settings for specified resource type
View configure-log-analytics.ps1
# Turn on log analytics diagnostics settings for specified resource type
$name = 'your subscription name goes here'
$subscription = Get-AzSubscription -SubscriptionName $name
Select-AzSubscription -SubscriptionName $name
$log_analytics_resource_group = 'log analytics resource group name'
$target_resource_group = 'resource group you want to setup'
$workspaces = Get-AzOperationalInsightsWorkspace -ResourceGroupName $log_analytics_resource_group
if (@($workspaces).Length -eq 0)
@chrismckelt
chrismckelt / DeployMaster.psm1
Created Jun 11, 2020
Azure Powershell deployment commands
View DeployMaster.psm1
$ErrorActionPreference = "Stop"
$global:_subscriptionId = $null
$global:_workload = $null
$global:_workloadCore = $null
$global:_regionCode = $null
$global:_storageAccount = $null
$global:_storageContext = $null
$global:_logicAppJson = $null
$breaker = '-------------------------------------------------------------------------------------------------------------------------------'
View TimescaleDB.cs
var connString = "Server=timescaledb;Port=5432;Database=postgres;User Id=postgres;Password=PASSWORD;";
using (var conn = new NpgsqlConnection(connString))
{
string sql = $"insert into Table_001 VALUES ('{p.TimeStamp}',{p.IsAirConditionerOn},{p.Temperature},'{p.TagKey}')";
await conn.OpenAsync();
using (var cmd = new NpgsqlCommand(sql, conn))
{
await cmd.ExecuteNonQueryAsync();
}
}
View TimescaleDB.sql
CREATE TABLE IF NOT EXISTS table_001
(
"Timestamp" timestamp with time zone not null,
IsAirConditionerOn smallint not null,
Temperature decimal not null,
tagkey varchar not null
);
ALTER TABLE table_001 OWNER TO postgres;
View TimescaleDB.json
{
"TimescaleDB": {
"version": "1.0",
"type": "docker",
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "${MODULES.TimescaleDb.debug}",
"createOptions": {
"HostConfig": {
View TimescaleDB.docker
FROM timescale/timescaledb:latest-pg11
ENV POSTGRES_USER postgres
ENV POSTGRES_DB postgres
ENV POSTGRES_PASSWORD m5asuFHqBE
COPY init.sql /docker-entrypoint-initdb.d/
@chrismckelt
chrismckelt / PipeMessage.cs
Created Mar 10, 2020
Azure IoT Edge demo PipeMessage.cs
View PipeMessage.cs
// This method is called whenever the module is sent a message from the EdgeHub. It just pipe the messages without any change.It prints all the incoming messages.
static async Task<MessageResponse> PipeMessage(Message message, object userContext) {
int counterValue=Interlocked.Increment(ref _counter);
var moduleClient=userContext as ModuleClient;
byte[] messageBytes=message.GetBytes();
string messageString=Encoding.UTF8.GetString(messageBytes);
if (!string.IsNullOrEmpty(messageString)) {
try {