Skip to content

Instantly share code, notes, and snippets.

View markheath's full-sized avatar

Mark Heath markheath

View GitHub Profile
@markheath
markheath / function.json
Last active February 12, 2017 22:09
Azure Functions simple in-memory CRUD web API
{
"bindings": [
{
"type": "httpTrigger",
"direction": "in",
"webHookTypeX": "genericJson",
"name": "req",
"methods": [
"get",
"post",
@markheath
markheath / ModelessMessage.cs
Created September 19, 2016 20:49
WinForms show a modeless message dialog
var f = new Form();
var b = new Button();
b.Text = "Show message";
b.AutoSize = true;
f.Controls.Add(b);
b.Click += (s, e) =>
{
var p = new Form();
p.Text = "Hello";
p.Show(f);
@markheath
markheath / LinqPerformance.cs
Created May 6, 2016 20:47
Simple PLINQ and LINQ Optimizer performance test
var listSize = 10000000;
var stopwatch = new Stopwatch();
stopwatch.Restart();
var s = Enumerable.Range(1, listSize)
.Select(n => n * 2)
.Select(n => Math.Sin((2 * Math.PI * n)/1000))
.Select(n => Math.Pow(n,2))
.Sum();
stopwatch.Stop();
Console.WriteLine("LINQ {0} items in {1}ms", listSize, stopwatch.ElapsedMilliseconds);
@markheath
markheath / Azure ServiceBus Filtered Subscriptions.linq
Last active August 2, 2019 10:32
Using filtered subscriptions in Azure Service Bus
<Query Kind="Program">
<Reference>&lt;RuntimeDirectory&gt;\System.Runtime.Serialization.dll</Reference>
<NuGetReference>WindowsAzure.ServiceBus</NuGetReference>
<Namespace>Microsoft.ServiceBus</Namespace>
<Namespace>Microsoft.ServiceBus.Messaging</Namespace>
</Query>
void Main()
{
string connectionString = Util.GetPassword("Test Azure Service Bus Connection String");
@markheath
markheath / advent-of-code-day-22.cs
Created December 22, 2015 10:46
Clumsy C# solution to advent of code day 22
// n.b. Linqpad script
class QueueSpellChooser : ISpellChooser
{
private Queue<Spell> spellQueue;
public QueueSpellChooser(IEnumerable<Spell> spells)
{
spellQueue = new Queue<Spell>(spells);
}
@markheath
markheath / build.bat
Last active April 24, 2023 21:24
Auto-download nuget.exe in F# FAKE build batch file
@echo off
cls
if not exist ".\.nuget" mkdir ".\.nuget"
if not exist ".\.nuget\nuget.exe" powershell -Command "Invoke-WebRequest https://www.nuget.org/nuget.exe -OutFile .\.nuget\nuget.exe"
".nuget\NuGet.exe" "Install" "FAKE" "-OutputDirectory" "packages" "-ExcludeVersion"
"packages\FAKE\tools\Fake.exe" build.fsx %*
pause
@markheath
markheath / MainWindow.xaml
Created April 18, 2015 15:30
WPF Button Styles
<Window x:Class="WpfButtonStyles.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF Example Button Styles" Height="350" Width="525">
<Window.Resources>
<Style
TargetType="Button" x:Key="NewGameButtonStyle">
<Setter Property="FontFamily" Value="Resources/teen bd.ttf#Teen" />
<Setter Property="FontSize" Value="18" />
<Setter Property="Template">
@markheath
markheath / DelayFadeOutSampleProvider.cs
Last active October 24, 2023 17:19
NAudio basic example of how to begin a fade out after a certain number of milliseconds have elapsed
// Define other methods and classes here
/// <summary>
/// Sample Provider to allow fading in and out
/// </summary>
public class DelayFadeOutSampleProvider : ISampleProvider
{
enum FadeState
{
Silence,
FadingIn,
@markheath
markheath / index.html
Last active November 20, 2015 05:59
Migrate from Syntax Highlighter to Highlight.js
<!DOCTYPE html>
<html lang=en-us>
<head>
<meta charset=utf-8><title>Highlight JS</title>
<meta name=viewport content="width=device-width, initial-scale=1.0, maximum-scale=1">
<link rel=stylesheet href=//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/tomorrow-night.min.css"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/languages/fsharp.min.js"></script>
@markheath
markheath / VerticalProgressBarStyles.xaml
Created November 6, 2014 11:27
WPF Vertical Progress Bar Styles
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<Style TargetType="ProgressBar" x:Key="Basic">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ProgressBar" >
<Grid x:Name="Root">
<Border