Skip to content

Instantly share code, notes, and snippets.

Avatar
🪐
Making the Cosmos (DB) better

Christopher Anderson christopheranderson

🪐
Making the Cosmos (DB) better
View GitHub Profile
@christopheranderson
christopheranderson / upsert-test.js
Created Oct 9, 2019
Test using upsert with condition on non-existing always succeeds
View upsert-test.js
//@ts-check
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";
const { CosmosClient } = require("@azure/cosmos");
const client = new CosmosClient({
endpoint: "https://localhost:8081",
key:
"C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="
});
@christopheranderson
christopheranderson / index.js
Created Mar 14, 2019
ChangeFeed hasMoreResults issue
View index.js
//@ts-check
const cosmos = require("@azure/cosmos");
const {items} = require("./sampleItems");
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;
const {CosmosClient} = cosmos;
const endpoint = process.env.COSMOS_ENDPOINT;
const key = process.env.COSMOS_KEY;
@christopheranderson
christopheranderson / index.ts
Created Aug 28, 2018
create-hmac typescript default import
View index.ts
import createHmac from "create-hmac";
const hmac = createHmac("sha256", "hello world").update("I love cupcakes").digest("hex");
console.log(hmac);
@christopheranderson
christopheranderson / body.json
Created Jan 9, 2018
Example context object for Azure Functions
View body.json
{
"invocationId": "a3ea24b8-d262-41d0-a57b-f6a207ade9c2",
"executionContext": {
"invocationId": "a3ea24b8-d262-41d0-a57b-f6a207ade9c2",
"functionName": "hello",
"functionDirectory": "C:\\workspace\\temp\\contextjs\\hello"
},
"log": "[FUNCTION]",
"bindingData": {
"invocationId": "a3ea24b8-d262-41d0-a57b-f6a207ade9c2",
@christopheranderson
christopheranderson / omg.cs
Last active Nov 15, 2017
Why would I do this?
View omg.cs
using System;
using System.Threading.Tasks;
using EdgeJs;
class Program
{
public static async Task Start()
{
var func = Edge.Func(@"
return function (data, callback) {
@christopheranderson
christopheranderson / run.csx
Created Sep 8, 2017
Factory/Singleton pattern in Azure Functions
View run.csx
public class StartUpWork {
private static StartUpWork _singleton;
private string initializeOnce;
public StartUpWork() {
// Do long startup tasks/create database connection pools/whatever you want to happen once
this.initializeOnce = "Woooooo!";
}
public static StartUpWork ensureStartUp() {
@christopheranderson
christopheranderson / host.json
Created May 10, 2017
Example config for App Insights pipeline
View host.json
{
"logger": {
"categoryFilter": {
"defaultLevel": "Information",
"categoryLevels": {
"Host.Results": "Error",
"Function": "Error",
"Host.Aggregator": "Information"
}
},
View gist:81475a0452e2df6dba7ab13faa97f741
{
"properties": {
"issue_description": {
"type": "number"
},
"issue_title": {
"type": "string"
}
},
"type": "object"
@christopheranderson
christopheranderson / query.sql
Created Apr 6, 2017
Analytics Query - Duration percentiles
View query.sql
requests
| where timestamp > ago(30m)
| summarize percentiles(duration, 50, 95, 99) by bin(timestamp, 1m)
| render timechart
@christopheranderson
christopheranderson / azuredeploy.json
Created Feb 10, 2017
Function App ARM template with MSDeploy
View azuredeploy.json
{
"$schema": "http://schemas.management.azure.com/schemas/2015-01-01-preview/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"appName": {
"type": "string",
"metadata": {
"description": "The name of the function app that you wish to create."
}
},