Skip to content

Instantly share code, notes, and snippets.

View markheath's full-sized avatar

Mark Heath markheath

View GitHub Profile
@markheath
markheath / Azure Blob Chunked Upload Parallel TPL V12.linq
Created March 10, 2023 14:31
Demonstration of fast Azure blob uploads using a producer consumer pattern with TPL dataflow and using parallel chunked uploads
string[] SizeSuffixes = { "bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
string SizeSuffix(long value, int decimalPlaces = 0)
{
if (value < 0)
{
throw new ArgumentException("Bytes should not be negative", "value");
}
var mag = (int)Math.Max(0, Math.Log(value, 1024));
var adjustedSize = Math.Round(value / Math.Pow(1024, mag), decimalPlaces);
return $"{adjustedSize} {SizeSuffixes[mag]}";
@markheath
markheath / Producer Consumer TPL
Created March 9, 2023 10:58
LINQPad demo of the producer consumer pattern with TPL dataflow including back-pressure
<Query Kind="Statements">
<Namespace>System.Collections.Concurrent</Namespace>
<Namespace>System.Threading.Tasks</Namespace>
<Namespace>System.Threading.Tasks.Dataflow</Namespace>
</Query>
var produceSpeed = TimeSpan.FromSeconds(0.5);
var produceCount = 20;
var consumeSpeed = TimeSpan.FromSeconds(2);
var maxParallelConsume = 4;
@markheath
markheath / run-from-package.ps1
Created January 14, 2019 16:57
Azure Web App run from package demo
$location = "West Europe"
$resGroupName = "RunFromPackageDemo"
az group create -n $resGroupName -l $location
$random = Get-Random -Minimum 10000 -Maximum 99999
$storageAccountName = "runfrompackage$random"
az storage account create -n $storageAccountName -g $resGroupName --sku "Standard_LRS"
$connectionString = az storage account show-connection-string -n $storageAccountName -g $resGroupName --query "connectionString" -o tsv
$env:AZURE_STORAGE_CONNECTION_STRING = $connectionString
@markheath
markheath / sfmesh-example-voting-app.json
Created October 24, 2018 13:57
Service Fabric Mesh voting app.
{
"$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"voteReplicaCount":{
"defaultValue": "1",
"type": "string",
"metadata": {
"description": "The number of service replicas for the vote service."
}
@markheath
markheath / docker-compose-v1.yml
Last active September 6, 2024 01:23
Elasticsearch docker compose examples
version: '2.2'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.4.1
container_name: elasticsearch
environment:
- cluster.name=docker-cluster
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
@markheath
markheath / Program.cs
Created March 30, 2017 20:07
Example WDL input driven resampling with NAuadio
void Main()
{
int outRate = 16000;
var inFile = @"E:\example input file.mp3";
var outFile = @"E:\Input Driven Resampled.wav";
using (var reader = new AudioFileReader(inFile))
using (var writer = new WaveFileWriter(outFile, WaveFormat.CreateIeeeFloatWaveFormat(outRate, reader.WaveFormat.Channels)))
{
var read = 0;
@markheath
markheath / index.html
Last active February 23, 2023 20:14
Flexbox simple blog layout
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="style.css" rel="stylesheet">
</head>
<body>
<div class="container">
@markheath
markheath / function.json
Last active November 21, 2016 20:33
F# Blob Bindings with Azure Functions
{
"bindings": [
{
"name": "inputBlob",
"type": "blobTrigger",
"direction": "in",
"path": "samples-workitems/input/{name}",
"connection": "AzureWebJobsDashboard"
},
{
@markheath
markheath / Azure Service Bus Batching Speed Test.csx
Last active October 31, 2016 17:47
Azure Service Bus Batching Speed Test
// (created in LINQPad with the following references and namespaces)
// <Query Kind="Statements">
// <Reference>&lt;RuntimeDirectory&gt;\System.Runtime.Serialization.dll</Reference>
// <NuGetReference>WindowsAzure.ServiceBus</NuGetReference>
// <Namespace>Microsoft.ServiceBus</Namespace>
// <Namespace>Microsoft.ServiceBus.Messaging</Namespace>
// </Query>
string connectionString = Util.GetPassword("Test Azure Service Bus Connection String");
const string queueName = "MarkHeathTestQueue";
@markheath
markheath / yahtzee.fs
Created October 25, 2016 20:12
Yahtzee Kata in F#
let highestRepeated dice minRepeats =
let repeats = dice |> List.countBy id |> List.filter (fun (_,n) -> n >= minRepeats) |> List.map fst
match repeats with | [] -> 0 | _ -> List.max repeats
let ofAKind n dice =
n * highestRepeated dice n
let sumOfSingle selected dice =
dice |> Seq.filter ((=) selected) |> Seq.sum