Skip to content

Instantly share code, notes, and snippets.

View sjwaight's full-sized avatar
😎
Happy Days

Simon Waight sjwaight

😎
Happy Days
View GitHub Profile
@sjwaight
sjwaight / run.csx
Last active November 27, 2016 09:46
Azure Function that uses a SendGrid output binding to send email.
#r "Microsoft.Azure.WebJobs.Extensions.SendGrid"
using SendGrid.Helpers.Mail;
public static void run(out Mail message)
{
// see the associted function.json & projcet.json files for how to get this working.
// function.json: https://gist.github.com/sjwaight/1394817ab84f8b6688a11be8621364fb
// project.json: https://gist.github.com/sjwaight/0c2392236b56ef914f0b4b10b786a8fb
@sjwaight
sjwaight / handle-braintree-response.cs
Last active December 8, 2016 22:31
Shows how you have to handle Braintree Transaction responses.
var brainTreeResponse = gateway.Transaction.Sale(btRequest);
Transaction transaction = null;
if (brainTreeResponse.IsSuccess())
{
transaction = brainTreeResponse.Target;
}
else
{
@sjwaight
sjwaight / asa-eh-func-run.csx
Created December 19, 2016 21:55
Demo of how to read an Event Hub / Stream Analytics / Service Bus message in an Azure Function
using Microsoft.ServiceBus.Messaging;
using Microsoft.ServiceBus;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public static void Run(BrokeredMessage sbQueueItem, TraceWriter log)
{
var yourRecord = sbQueueItem.GetBody<string>();
var paymenRequest = JObject.Parse(yourRecord);
var vendorId = paymenRequest.SelectToken("vendorId").ToString();
@sjwaight
sjwaight / bt-func-project.json
Created January 20, 2017 04:12
Function project.json showing what's required to post payments to Braintree's v.zero API.
{
"frameworks": {
"net46": {
"dependencies": {
"Braintree": "3.4.0",
}
}
}
}
@sjwaight
sjwaight / bt-run.csx
Last active January 20, 2017 09:15
Azure Function main entry point showing how to do payments using Braintree's v.zero API.
using System;
using Braintree;
public static void Run(string input, TraceWriter log)
{
var braintreeEnvironment = "sandbox"; // alternative = production
// These three config items should be stored in Azure KeyVault
var merchantId = "5xxxxxxxxxxxxxx7";
var merchPubKey = "tyyyyyyyyyyyyyyh";
@sjwaight
sjwaight / web.config
Last active February 11, 2017 12:19
Sample web.config ready for transformation by Web Deploy.
<configuration>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="LoggingDatabaseAccount" value="__docdburi__" />
<add key="LoggingDatabaseKey" value="__docdbkey__" />
<add key="LoggingDatabase" value="__loggingdb__" />
<add key="LoggingDatabaseCollection" value="__loggingdbcollection__" />
@sjwaight
sjwaight / parameters.xml
Last active February 11, 2017 06:17
Sample tokenisation parameters file for use with Web Deploy
<parameters>
<parameter name="IIS Web Application Name" description="IIS Web Application Name" defaultvalue="__iisappname__">
<parameterentry kind="ProviderPath" scope="IiSApp" match="@defaultvalue"/>
</parameter>
<parameter name="LoggingDatabaseAccount" description="Main Document DB Account" defaultvalue="__docdburi__">
<parameterentry kind="XmlFile" scope="\\Web.config$" match="/configuration/appSettings/add[@key='LoggingDatabaseAccount']/@value"/>
</parameter>
<parameter name="LoggingDatabaseKey" description="Key to access Main Document DB Account" defaultvalue="__docdbkey__">
<parameterentry kind="XmlFile" scope="\\Web.config$" match="/configuration/appSettings/add[@key='LoggingDatabaseKey']/@value"/>
</parameter>
@sjwaight
sjwaight / ManageNsgOnDeployment.ps1
Last active February 28, 2017 02:15
PowerShell script to help manage an Azure VNet NSG rule.
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]$resourceGroupName,
[Parameter(Mandatory=$True)]
[string]$networkSecurityGroupName,
[Parameter(Mandatory=$True)]
[string]$securityRuleName,
[Parameter(Mandatory=$True)]
[string]$allowOrDeny,
@sjwaight
sjwaight / gab-api-demo-deployment.yaml
Last active April 27, 2017 11:14
Kubernetes deployment file for Global Azure Bootcamp 2017 Session.
apiVersion: v1
kind: Service
metadata:
name: gabdemo
spec:
ports:
- port: 80
selector:
app: gabdemo
type: LoadBalancer
@sjwaight
sjwaight / create-azure-mysql.sh
Last active June 29, 2017 06:29
bash script you can use to create an Azure Database for MySQL server instance
#!/bin/sh
azuresub=$1
demolocation=$2
demoresourcegroup=$3
mysqlservername=$4
mysqladminuser=$5
mysqladminpass=$6
# uncomment to add local support and login to your Azure subscription