Skip to content

Instantly share code, notes, and snippets.

@vainolo
vainolo / NetworkFileCopier.java
Created May 6, 2012 21:27
NetworkFileCopier.java
/*******************************************************************************
* Copyright (c) 2012 Arieh 'Vainolo' Bibliowicz
* You can use this code for educational purposes. For any other uses
* please contact me: vainolo@gmail.com
*******************************************************************************/
package com.vainolo.examples.net;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
@vainolo
vainolo / ZipExtracter.java
Created May 8, 2012 09:17
ZipExtracter.java
/*******************************************************************************
* Copyright (c) 2012 Arieh 'Vainolo' Bibliowicz
* You can use this code for educational purposes. For any other uses
* please contact me: vainolo@gmail.com
*******************************************************************************/
package com.vainolo.examples.file;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
@vainolo
vainolo / afp3_1.cs
Last active October 25, 2018 10:44
Azure Functions – Part 3: Handling HTTP Query GET and POST Requests - Sample Function Code
using System.Net;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
// parse query parameter
string name = req.GetQueryNameValuePairs().FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0).Value;
if (name == null)
{
// Get request body
dynamic data = await req.Content.ReadAsAsync<object>();
@vainolo
vainolo / afp3_2.cs
Last active October 25, 2018 10:47
Azure Functions – Part 3: Handling HTTP Query GET and POST Requests - GET and POST handling code
#r "Newtonsoft.Json"using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
string name = null;
if (req.Method == HttpMethod.Post)
{
log.Info($"POST method was used to invoke the function");
@vainolo
vainolo / afp2_1.cs
Created October 25, 2018 13:02
Azure Functions – Part 2: Serving HTML Pages with Azure Functions - Option 1
using System.Net;
using System.Net.Http.Headers;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
// Option 1, coded HTML
var response = req.CreateResponse(HttpStatusCode.OK, "Hello ");
response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
@vainolo
vainolo / afp2_2.html
Created October 25, 2018 13:04
Azure Functions – Part 2: Serving HTML Pages with Azure Functions - Web Page
<html>
<head>
<title>Hello</title>
</head>
<body>
World
</body>
</html>
@vainolo
vainolo / afp2_3.cs
Created October 25, 2018 13:05
Azure Functions – Part 2: Serving HTML Pages with Azure Functions - Option 2
// Option 2, read from local file
var response = new HttpResponseMessage(HttpStatusCode.OK);
var stream = new FileStream(@"d:\home\site\wwwroot\HelloWorldHTML\hello.html", FileMode.Open);
response.Content = new StreamContent(stream);
response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
return response;
@vainolo
vainolo / afp2_4.cs
Created October 25, 2018 13:06
Azure Functions – Part 2: Serving HTML Pages with Azure Functions - Option 3 - headers
#r "Microsoft.WindowsAzure.Storage"
using System.Net;
using System.Net.Http.Headers;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
@vainolo
vainolo / afp2_5.cs
Created October 25, 2018 13:07
Azure Functions – Part 2: Serving HTML Pages with Azure Functions - Option 3 - body
// Option 3, read from external blob
var storageAccount = CloudStorageAccount.Parse("[your azure storage connection string]");
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("site");
var blob = container.GetBlockBlobReference("hello.html");
string text = "";
using (var memoryStream = new MemoryStream())
{
blob.DownloadToStream(memoryStream);
text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray());
@vainolo
vainolo / afp1_1.cs
Created October 25, 2018 13:10
Azure Functions – Part 1: Getting Started - Example
using System.Net;
public static async Task&amp;lt;HttpResponseMessage&amp;gt; Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
return req.CreateResponse(HttpStatusCode.OK, "Hello World");
}