Skip to content

Instantly share code, notes, and snippets.

View jpda's full-sized avatar
🤔
ok

John Patrick Dandison jpda

🤔
ok
View GitHub Profile
@jpda
jpda / graph-nolib.py
Created January 25, 2019 20:24
Microsoft Graph from Python only using requests
import logging
import requests
import json
def main():
client_id = "<CLIENT ID>"
client_secret = "<CLIENT SECRET>"
resource_id = "https://graph.microsoft.com"
tenant = "<TENANT NAME OR GUID> (like microsoft.com or jpd.ms)"
graph_query = "<GRAPH PATH> - example: users/john@jpd.ms"
@jpda
jpda / init-manual-service-principal.py
Last active June 16, 2019 23:08
Key Vault with azure functions python
import logging
import azure.functions as func
from azure.keyvault import KeyVaultClient, KeyVaultAuthentication
from azure.common.credentials import ServicePrincipalCredentials
# see https://docs.microsoft.com/en-us/python/api/overview/azure/key-vault?view=azure-python
def auth_callback(server, resource, scope):
credentials = ServicePrincipalCredentials(
client_id = '<CLIENT ID>',
@jpda
jpda / Thing.cs
Created January 24, 2019 15:29
Azure OCR sample
class Program
{
static void Main(string[] args)
{
// once you create a computer vision service in Azure, you'll get the region and service key
// CV OCR docs are here: https://eastus2.dev.cognitive.microsoft.com/docs/services/56f91f2d778daf23d8ec6739/operations/56f91f2e778daf14a499e1fc
var recognizer = new Recognizer("<REGION OF YOUR CV SERVICE>", "<CV SERVICE KEY>");
// here's an example if the image to OCR is on the internet somewhere already
recognizer.RecognizeFromImageUrl("<URL TO IMAGE, IF AVAILABLE ON INTERNET>", "ar").Wait();
@jpda
jpda / Contact.cs
Last active June 14, 2022 10:55
Xamarin.Android RecylerView adapter
public class Contact
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("email")]
public string Email { get; set; }
}
@jpda
jpda / function.proj
Last active July 24, 2018 22:06
Simple graph query by attribute
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="3.19.8" />
</ItemGroup>
</Project>
@jpda
jpda / add.ps1
Created March 27, 2018 21:48
add MSI service principal to approle
# you may not need tenantId, but if it is ambiguous you should set it here
Connect-AzureAd -TenantId
# name of your MSI service principal, in my case msi-func. You can also get the ID from Enterprise Applications in AAD (not App Reg)
$msifunc = Get-AzureADServicePrincipal -SearchString "msi-func"
# name of your AAD service principal, in my case aad-func. You can also get the ID from App Registrations in AAD
$aadapp = Get-AzureADServicePrincipal -SearchString "aad-func"
# Id - the ID of the role. You can get it from the app's manifest
# PrincipalId - the object ID of the MSI principal
# ObjectId - the object ID of the MSI principal
{
"frameworks":{
"net46": {
"dependencies": {
"Microsoft.Azure.Services.AppAuthentication": "1.1.0-preview"
}
}
}
}
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using Microsoft.Azure.Services.AppAuthentication;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
var target = "<target app client ID>";
var azureServiceTokenProvider = new AzureServiceTokenProvider();
string accessToken = await azureServiceTokenProvider.GetAccessTokenAsync(target);
@jpda
jpda / aad-func.csx
Last active March 27, 2018 22:00
azure ad protected function
using System.Net;
using System.Security.Claims;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
var stuff = System.Security.Claims.ClaimsPrincipal.Current.Claims.Select(x => new { x.Type, x.Value });
return req.CreateResponse(HttpStatusCode.OK, stuff);
}
@jpda
jpda / chromium-updater.ps1
Created March 12, 2018 20:47
chromium win64 updater
param(
[string]$InstallDir = "drive:\path\to\folder\chrome-win32",
[switch]$Verbose = $false
)
$rootDir = $InstallDir
$latest = Invoke-WebRequest -Uri "https://www.googleapis.com/storage/v1/b/chromium-browser-snapshots/o/Win_x64%2FLAST_CHANGE" -Verbose:$Verbose
$data = ConvertFrom-Json -InputObject $latest.Content
$build = $data.metadata.'cr-commit-position-number'
Write-Host Latest is $build, looking for your version...