Skip to content

Instantly share code, notes, and snippets.

View markheath's full-sized avatar

Mark Heath markheath

View GitHub Profile
@markheath
markheath / XhtmlToMarkdownConverter.cs
Created February 15, 2012 19:07
Convert XLST to Markdown with C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.IO;
using System.Reflection;
using System.Xml;
@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 / 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 / recursive-factorise-1.fs
Last active December 27, 2015 08:19
recursive factorization function in F#
let rec f n x acc =
if x = n then
x::acc
elif n % x = 0 then
f (n/x) x (x::acc)
else
f n (x+1) acc
let factorise n = f n 2 []
let factors = factorise 124782
@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 / 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";
@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 / 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 / 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;