Skip to content

Instantly share code, notes, and snippets.

View jeffhollan's full-sized avatar
❄️
Working

Jeff Hollan jeffhollan

❄️
Working
View GitHub Profile
{
"properties": {
"request": {
"properties": {
"inDialog": {
"type": "boolean"
},
"intent": {
"properties": {
"name": {
#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage.Table;
using System.Net;
public static HttpResponseMessage Run(HttpRequestMessage req, IQueryable<Person> oncallTable, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
var startOfWeek = DateTimeExtension.StartOfWeek(DateTime.Now, DayOfWeek.Monday);
@jeffhollan
jeffhollan / retrieveSecret.cs
Last active November 23, 2017 04:30
Azure Funciton Service Principal
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json.Linq;
using Microsoft.Azure.Services.AppAuthentication;
using Microsoft.Azure.KeyVault;
{
"runtimeStatus": "Completed",
"input": {
"$type": "HttpToDurable.ProcessRequest, HttpToDurable",
"data": "some data"
},
"output": [
"some response data"
],
"createdTime": "2017-11-25T23:02:35Z",
@jeffhollan
jeffhollan / sample.cs
Last active December 7, 2017 19:01
Processing multiple poison queus with functions
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
namespace FunctionApp5
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run1([QueueTrigger("queue1-poison")]dynamic message, TraceWriter log)
@jeffhollan
jeffhollan / eventgrid.js
Created December 20, 2017 07:55
Emit Event to Event Grid from an Azure Function
function EmitEvent(ringEvent, context, callback) {
context.log('Sending event to event grid.');
var eventGridPayload = [{
id: utils.generateUUID(),
eventType: ringEvent['kind'],
subject: 'ring/frontDoor',
eventTime: new Date().toISOString(),
data: ringEvent
}];
var response = '';
@jeffhollan
jeffhollan / addRingToCosmos.js
Created December 21, 2017 06:12
From the Ring.com project - one of the functions
const utils = require('../function-utils');
module.exports = function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
var ringData = req.body[0];
ringData['id'] = ringData['id'] || utils.generateUUID();
context.log(ringData);
context.bindings.ringDocument = JSON.stringify(ringData);
[FunctionName("watcher")]
public static async Task RunOrchestrator(
[OrchestrationTrigger] DurableOrchestrationContext context, TraceWriter log)
{
log.Info("Starting watcher - getting initial ticker");
WatcherRequest input = context.GetInput<WatcherRequest>();
double current = await context.CallActivityAsync<double>("watcher_getticker", input.market);
DateTime maxTime = context.CurrentUtcDateTime.Add(input.maxDuration);
while (current < input.threshold && context.CurrentUtcDateTime < maxTime) {
await context.CreateTimer(context.CurrentUtcDateTime.AddMinutes(double.Parse(Constants.DelayInterval)), CancellationToken.None);
[FunctionName("watcher_getticker")]
public static async Task<double> GetTicker([ActivityTrigger] string name, TraceWriter log)
{
var result = await (await Bittrex.httpClient.GetAsync(Constants.TickerUrl + "?market=" + name)).Content.ReadAsAsync<JObject>();
return (double)result["result"]["Bid"];
}
[FunctionName("send_event")]
public static async Task SendMessage([ActivityTrigger] Message message, TraceWriter log)
{
@jeffhollan
jeffhollan / EventGridTrigger.cs
Last active January 25, 2018 23:54
Event Grid trigger as HTTP with validation handling
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json.Linq;
namespace EventGridDocs
{