Skip to content

Instantly share code, notes, and snippets.

View bechynsky's full-sized avatar
😺

Štěpán Bechynský bechynsky

😺
  • Microsoft
  • Prague, Czech republic
  • X @stepanb
View GitHub Profile
@bechynsky
bechynsky / get_group_members_msgraph.ps1
Created July 1, 2021 12:06
Simple demo how to get list of group members using Microsoft Graph for M365
# https://docs.microsoft.com/en-us/graph/powershell/installation
# https://docs.microsoft.com/en-us/graph/powershell/get-started
# https://developer.microsoft.com/en-us/graph/graph-explorer
# https://tech.nicolonsky.ch/exploring-the-new-microsoft-graph-powershell-modules/
Connect-MgGraph -Scopes "User.Read.All", "GroupMember.Read.All", "Group.Read.All", "Directory.Read.All"
$GROUP_NAME = 'Workspace'
$group = Get-MgGroup -Filter "DisplayName eq '$GROUP_NAME'"
@bechynsky
bechynsky / climate_module_to_database.py
Created February 10, 2021 19:09
Saves temperature from Hardwario Climate module to MariaDB
# https://tower.hardwario.com/en/latest/hardware/about-climate-module/
#
# MariaDB database setup
#
# create database climate;
# create user 'python'@'localhost' identified by 'Pyth0n';
# grant all privileges on climate.* to 'python'@'localhost';
# FLUSH PRIVILEGES;
#
# create table temperature(
@bechynsky
bechynsky / climate_module_static_website.py
Created February 9, 2021 16:53
Create static file from Hardwario Climate module and publish it to Azure Storage Static website
# https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website-how-to?tabs=azure-portal
# https://tower.hardwario.com/en/latest/hardware/about-climate-module/
import os
import datetime
from paho.mqtt import client as mqtt
from azure.storage.blob import BlobClient
from azure.storage.blob import ContentSettings
@bechynsky
bechynsky / iotcentral_meteo_rpi_sense_hat.py
Created January 22, 2021 09:50
Simple Azure IoT Hub demo for Sense Hat
# https://pypi.org/project/azure-iot-device/
from azure.iot.device import IoTHubDeviceClient, Message
from sense_hat import SenseHat
sense = SenseHat()
t = sense.get_temperature()
h = sense.get_humidity()
p = sense.get_pressure()
@bechynsky
bechynsky / CustomVisionClassification.js
Created January 21, 2021 07:30
Quickstart: Create an image classification project with the Custom Vision client library
// https://docs.microsoft.com/en-us/azure/cognitive-services/Custom-Vision-Service/quickstarts/image-classification?tabs=visual-studio&pivots=programming-language-javascript
const util = require('util');
const fs = require('fs');
const TrainingApi = require("@azure/cognitiveservices-customvision-training");
const PredictionApi = require("@azure/cognitiveservices-customvision-prediction");
const msRest = require("@azure/ms-rest-js");
const trainingKey = "";
const predictionKey = "";
@bechynsky
bechynsky / CustomVisionObjectDetection.js
Created January 21, 2021 07:28
Quickstart: Create an object detection project with the Custom Vision client library
// https://docs.microsoft.com/en-us/azure/cognitive-services/Custom-Vision-Service/quickstarts/object-detection?tabs=visual-studio&pivots=programming-language-javascript
const util = require('util');
const fs = require('fs');
const TrainingApi = require("@azure/cognitiveservices-customvision-training");
const PredictionApi = require("@azure/cognitiveservices-customvision-prediction");
const msRest = require("@azure/ms-rest-js");
const trainingKey = "";
const predictionKey = "";
@bechynsky
bechynsky / azurestoragesample.cs
Last active January 11, 2021 15:13
Sample for Azure Storage account, AZ-204, DP-200
/*
You neeed to create App.config file with this content
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="storage" value="YOUR CONNECTION SRING TO AZURE STORAGE ACCOUNT" />
</appSettings>
</configuration>
@bechynsky
bechynsky / vision_101.py
Created January 5, 2021 14:36
Simple demo Azure Cognitive Services Vision REST API
import requests
from pprint import pprint
subscription_key = ''
endpoint = ''
api_url = endpoint + 'vision/v3.1/analyze'
image_url = ''
headers = {'Ocp-Apim-Subscription-Key': subscription_key,
'Content-Type': 'application/json'}
@bechynsky
bechynsky / rpi_camera_to_blob_storage.py
Created January 5, 2021 14:32
Get picture from Raspberry Pi Camera and uplouad to Azure Storage Container
from picamera import PiCamera
from azure.storage.blob import BlobServiceClient, BlobClient, BlobSasPermissions, generate_blob_sas
from datetime import datetime, timedelta
# You need to create container first
container_name = ''
account_name = ''
key = ''
connection_string = 'DefaultEndpointsProtocol=https;AccountName=' + account_name + ';AccountKey=' + key + ';EndpointSuffix=core.windows.net'
@bechynsky
bechynsky / create_cosmosdb.sh
Last active January 12, 2021 09:53
Creates Cosmos DB resource, database and collection. Designed for Cloud Shell
export RESOURCE_GROUP=""
export RESOURCE_NAME=""
export LOCATION=""
export DB_NAME=""
export COLLECTION=""
export PARTITION_KEY=""
az group create --name $RESOURCE_GROUP --location $LOCATION
az cosmosdb create --name $RESOURCE_NAME --kind GlobalDocumentDB --resource-group $RESOURCE_GROUP
az cosmosdb sql database create --name $DB_NAME --account-name $RESOURCE_NAME --resource-group $RESOURCE_GROUP