Skip to content

Instantly share code, notes, and snippets.

View markheath's full-sized avatar

Mark Heath markheath

View GitHub Profile
@markheath
markheath / docker-compose-v1.yml
Last active February 24, 2024 01:01
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 / AudioPlaybackEngine.cs
Created February 3, 2014 13:42
FireAndForget NAudio Sample
using System;
using NAudio.Wave;
using NAudio.Wave.SampleProviders;
namespace FireAndForgetAudioSample
{
class AudioPlaybackEngine : IDisposable
{
private readonly IWavePlayer outputDevice;
private readonly MixingSampleProvider mixer;
@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 / 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 / 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 / ButtonStackPanel.xaml
Created May 29, 2014 13:55
Example WPF Button Template
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Page.Resources>
<Style x:Key="MyFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Control}">
<Grid Margin="3 2">
@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 / 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 / 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 / simplequiz.html
Created October 9, 2012 15:40
Experimenting with JQuery to make a simple quiz framework
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Simple JQuery Quiz</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>