Skip to content

Instantly share code, notes, and snippets.

@ahelland
ahelland / BenderToTeams.csx
Created November 15, 2016 19:57
Azure Function for sending a message through an incoming WebHook in Microsoft Teams
#r "Newtonsoft.Json"
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net.Http.Headers;
using System.Collections.Generic;
public static void Run(string input, TraceWriter log)
{
var statusMsg = "Bender says: Get up meatbag!";
@ahelland
ahelland / ADFSSRS.csx
Created September 6, 2016 09:02
Azure Function returning word pairs
using System.Net;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info($"C# HTTP trigger function processed a request. RequestUri={req.RequestUri}");
var responseMsg = String.Empty;
Random r = new Random();
int rInt = r.Next(0,4);
responseMsg = GetQuote(rInt);
@ahelland
ahelland / RandomTrigger.csx
Last active August 29, 2016 19:33
Azure Function running on a self-modifying random schedule
using System;
using System.IO;
public static void Run(TimerInfo myTimer, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
//Read current settings
string[] settings = File.ReadAllLines(@"D:\home\site\wwwroot\RandomTrigger\function.json");
var schedule = settings[6];
@ahelland
ahelland / BenderFromSlack.csx
Last active June 23, 2019 23:45
Azure Function for receiving and processing an outbound WebHook from Slack
#r "Newtonsoft.Json"
#r "System.Web.Extensions"
#r "System.Web"
using System;
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Web;
using System.Web.Script.Serialization;
using System.Linq;
@ahelland
ahelland / BenderToSlack.csx
Created July 12, 2016 07:48
Azure Function for sending a message through an incoming WebHook in Slack
#r "Newtonsoft.Json"
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net.Http.Headers;
using System.Collections.Generic;
public static void Run(string input, TraceWriter log)
{
var statusMsg = "Bender says: Get up meatbag!";
@ahelland
ahelland / RemoteCompile.cs
Created June 28, 2016 18:11
Snippet (based on a Universal App) for remote compiling and running .Net code using a Microsoft .Net API endpoint
using Newtonsoft.Json;
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.Web.Http;
using static System.Environment;
namespace RemoteCompile
{
@ahelland
ahelland / GithubWebhookDeployFile.csx
Created June 23, 2016 10:34
Azure Function for receiving a Github Webhook, and in turn running a WAWSDeploy of a specific file to an Azure Web App
#r "Microsoft.Web.Deployment.dll"
using System;
using System.IO;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
using System.Diagnostics;
using Microsoft.Web.Deployment;
using System.Collections.Generic;
using System.Collections.Specialized;
@ahelland
ahelland / JwtCracker.cs
Created June 14, 2016 18:51
Method to decode a JWT and pretty print the JSON contents
//Assume the input is in a control called txtJwtIn,
//and the output will be placed in a control called txtJwtOut
var jwtHandler = new JwtSecurityTokenHandler();
var jwtInput = txtJwtIn.Text;
//Check if readable token (string is in a JWT format)
var readableToken = jwtHandler.CanReadToken(jwtInput);
if(readableToken != true)
{
@ahelland
ahelland / EASBlobTrigger.csx
Created May 31, 2016 08:15
BlobTriggered Function for processing WBXML returned from Exchange ActiveSync
#r "EAS Protocol.dll"
#r "System.Xml.Linq.dll"
using System;
using System.Xml.Linq;
using EAS_Protocol.WBXML;
public static void Run(string myBlob, TraceWriter log)
{
log.Info($"C# Blob trigger function processed: {myBlob}");
var response = myBlob.Split(';');
@ahelland
ahelland / EASQueueTrigger.csx
Created May 31, 2016 08:04
QueueTriggered Function for processing HTTP Status Codes returned from Exchange ActiveSync
using System;
public static void Run(string myQueueItem, out object statusDocument, TraceWriter log)
{
log.Info($"C# Queue trigger function processed: {myQueueItem}");
var status = myQueueItem.Split(';');
log.Info($"Guid: {status[0]}, StatusCode: {status[1]}");
var guid = status[0];
var resCode = status[1];