Skip to content

Instantly share code, notes, and snippets.

@LeeCampbell
LeeCampbell / ObservableEx_ThrottledBuffer.cs
Created December 7, 2016 05:23
ThrottledBuffer for Rx
public static partial class ObsEx
{
public static IObservable<IList<T>> ThrottledBuffer<T>(this IObservable<T> source, TimeSpan period, IScheduler scheduler)
{
return Observable.Create<IList<T>>(obs =>
{
var yieldTimer = new SerialDisposable();
var buffer = new List<T>();
Action yeildBuffer = () => {
//Not on same thread, so need to be careful here.
@LeeCampbell
LeeCampbell / IncrementBenchmarks.cs
Last active December 1, 2016 08:46
Benchmark via gist sample
using System.Threading;
using BenchmarkDotNet.Attributes;
public class IncrementBenchmarks
{
private int _intValue;
private long _longValue;
[Setup]
public void Setup()
@LeeCampbell
LeeCampbell / InstallSqlForDev.ps1
Created November 15, 2016 08:40
Install SQL 2016 Dev command line (Powershell)
#Installs SQL Server locally with standard settings for Developers/Testers.
# Install SQL from command line help - https://msdn.microsoft.com/en-us/library/ms144259.aspx
$sw = [Diagnostics.Stopwatch]::StartNew()
$currentUserName = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name;
$SqlServerIsoImagePath = "???\Downloads\Microsoft\SQL Server 2016 Developer Edition\en_sql_server_2016_developer_x64_dvd_8777069.iso"
#Mount the installation media, and change to the mounted Drive.
$mountVolume = Mount-DiskImage -ImagePath $SqlServerIsoImagePath -PassThru
$driveLetter = ($mountVolume | Get-Volume).DriveLetter
$drivePath = $driveLetter + ":"
@LeeCampbell
LeeCampbell / ProjectDependencies.cs
Created November 3, 2016 05:41
LinqPad Script that generates the GraphViz file to visualize dependencies.
void Main()
{
//Generates the .gv file content that can be put into GraphViz to vizualize your dependency tree.
// Once in GrpahViz, export to svg to avoid guessing how big you will need it (e.g. compared to PNG/JPG or other raster formats)
var rootPath = @"C:\source\GitHub\Mercury";
var outputPath = @"C:\source\GitHub\Mercury\references.dot";
var limit = 1000;
var projects = Directory.GetFiles(rootPath, "*.csproj", SearchOption.AllDirectories)
.Where(path=>!path.ToLowerInvariant().Contains("test")) //Exclude tests for sanity
@LeeCampbell
LeeCampbell / ReportCodeDuplication.ps1
Last active November 11, 2016 01:15
Code Duplication command line reporter. Uses Jetbrains cmdline tools.
#From https://download.jetbrains.com/resharper/JetBrains.ReSharper.CommandLineTools.2016.2.20160913.100041.zip
$codeDupFolder = 'C:\Users\lee.campbell\Downloads\JetBrains.ReSharper.CommandLineTools.2016.2.20160913.100041\'
$codeDuplicateExe = $codeDupFolder + '\dupfinder.exe'
$codeDuplicateXsl = $codeDupFolder + '\dupFinder.xsl'
$xmlOutput = 'C:\Users\lee.campbell\Desktop\LoanServiceSlnDupes.xml'
$htmlOutput = 'C:\Users\lee.campbell\Desktop\LoanServiceSlnDupes.html'
.$codeDuplicateExe --show-text --output="$xmlOutput" -e="**/*.Designer.cs" -e="**/*.generated.cs" -e="**/*Test*/**/*.cs" -e="**/*Event.cs" 'C:\Source\GitHub\Mercury\src\Mercury.LoanService.sln'
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform;
@LeeCampbell
LeeCampbell / IRunnable.cs
Last active July 29, 2016 01:24
SerialDisposable Perf Tests
namespace RxPerformanceTest.SerialDisposable.Console
{
interface IRunnable
{
ThroughputTestResult[] Run();
}
}
@LeeCampbell
LeeCampbell / LeftFold.cs
Created May 11, 2016 08:35
An example of a LeftFold helper for Cedar EventStore lib.
using System;
using System.Collections.Generic;
using System.Globalization;
using Cedar.EventStore.Streams;
namespace DunkyMoleFanClub
{
public static class LeftFold
{
public static readonly string DefaultKey = string.Empty;
@LeeCampbell
LeeCampbell / PerfTest.cs
Created October 11, 2015 15:28
Simple LinqPad sample of how to execute a performance test in C#
void Main()
{
var messageCount = 10000;
var sum =0L;
var result = ThroughputTestResult.Capture(messageCount, () => sum = SumOfSquares(messageCount));
Console.WriteLine($"Result: SumOfSquares({messageCount}) = {sum}");
Console.WriteLine(result.ToString());
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using EventStore.ClientAPI;
leecampbell@lxc-vm:~$ sed -i 's/\r//' kafka.sh
leecampbell@lxc-vm:~$ bash kafka.sh
in the file
lxc-net stop/waiting
lxc-net start/running
Setting up the GPG keyring
ERROR: Unable to fetch GPG key from keyserver.
lxc_container: lxccontainer.c: create_run_template: 1125 container creation template for zookeeper failed
lxc_container: lxc_create.c: main: 271 Error creating container zookeeper