Skip to content

Instantly share code, notes, and snippets.

Matias Quaranta ealsur

Block or report user

Report or block ealsur

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ealsur
ealsur / function.json
Last active Jan 19, 2018
Azure Cosmos DB + Functions Cookbook - HTTP query json
View function.json
{
"bindings": [
{
"name": "query",
"type": "httpTrigger",
"direction": "in"
},
{
"name": "$return",
"type": "http",
@ealsur
ealsur / run.csx
Last active Jan 19, 2018
Azure Cosmos DB + Functions Cookbook - HTTP query csx
View run.csx
#r "System.Runtime.Serialization"
using System.Net;
using System.Runtime.Serialization;
// Define the class that will get sent on the HTTP body
// DataContract is used to support XML
[DataContract(Name = "Query", Namespace = "http://functions")]
public class Query {
@ealsur
ealsur / index.js
Created Jan 19, 2018
Azure Cosmos DB + Functions Cookbook - HTTP query nodejs
View index.js
module.exports = function (context, req) {
var documents = context.bindings.documents;
var totalDocuments = documents.length;
context.log('Found '+ totalDocuments +' documents');
if(totalDocuments === 0){
context.res = {
status: 404,
body : "No documents found"
};
@ealsur
ealsur / wrong-run.csx
Last active Jan 22, 2018
Azure Cosmos DB + Functions Cookbook: static client (wrong scenario)
View wrong-run.csx
#r "Microsoft.Azure.Documents.Client"
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using System.Net;
private static string endpointUrl = ConfigurationManager.AppSettings["cosmosDBAccountEndpoint"];
private static string authorizationKey = ConfigurationManager.AppSettings["cosmosDBAccountKey"];
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
@ealsur
ealsur / function.json
Created Jan 30, 2018
Azure Cosmos DB + Functions Cookbook - output collector function.json
View function.json
{
"bindings": [
{
"name": "classes",
"type": "httpTrigger",
"direction": "in"
},
{
"name": "$return",
"type": "http",
@ealsur
ealsur / run.csx
Created Jan 30, 2018
Azure Cosmos DB + Functions Cookbook - output collector run.csx
View run.csx
using System.Net;
public class MyClass {
public string id {get;set;}
public string name {get;set;}
}
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, MyClass[] classes, TraceWriter log, IAsyncCollector<MyClass> documentsToStore)
{
log.Info($"Detected {classes.Length} incoming documents");
@ealsur
ealsur / index.js
Created Jan 30, 2018
Azure Cosmos DB + Functions Cookbook - output collector index.js
View index.js
module.exports = function (context, req) {
context.log('Detected ' + req.body.length + ' incoming documents');
context.bindings.documentsToStore = [];
for(let i = 0, len=req.body.length; i<len;i++){
const doc = req.body[i];
context.bindings.documentsToStore.push(doc);
}
context.done(null, {
@ealsur
ealsur / data.json
Created Jan 30, 2018
Azure Cosmos DB + Functions Cookbook - output collector sample payload
View data.json
[
{
"id":"1",
"name": "John",
"surname": "McClane"
},
{
"id":"2",
"name": "John",
"surname": "Rambo"
@ealsur
ealsur / index.js
Created Feb 6, 2018
Azure Cosmos DB + Functions Cookbook - live migration index.js
View index.js
module.exports = function(context, input) {
if(!!input && input.length > 0){
context.bindings.docsToSave = [];
for(let i = 0, len=input.length; i<len;i++){
const doc = input[i];
// Do something here with the doc or create a new one
context.bindings.docsToSave.push(doc);
}
}
@ealsur
ealsur / run.csx
Created Feb 6, 2018
Azure Cosmos DB + Functions Cookbook - live migration run.csx
View run.csx
#r "Microsoft.Azure.Documents.Client"
using System;
using System.Collections.Generic;
using Microsoft.Azure.Documents;
public static async Task Run(IReadOnlyList<Document> input, IAsyncCollector<Document> docsToSave)
{
foreach(var doc in input){
// work with the document, process or create a new one
await docsToSave.AddAsync(doc);
You can’t perform that action at this time.