Skip to content

Instantly share code, notes, and snippets.

View markheath's full-sized avatar

Mark Heath markheath

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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
@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";