Skip to content

Instantly share code, notes, and snippets.

@AndyPook
AndyPook / Queuehandler.cs
Last active March 9, 2016 14:05
Allows for separation of a producer (eg a network receiver) from a potentially more expensive consumer
public class QueueHandler<T>
{
public static QueueHandler<T> Start(Action<T> handler, CancellationToken? token = null, ParallelOptions options = null)
{
var q = new QueueHandler<T>(handler, token, options);
q.Start();
return q;
}
public QueueHandler(Action<T> handler, CancellationToken? token = null, ParallelOptions options = null)
@AndyPook
AndyPook / Arrays.cs
Last active March 9, 2016 14:01
Equivalent of Enumerable.Empty<T> but returns an ICollection<T> (an empty array)
public static class Arrays
{
public static T[] Empty<T>() { return EmptyArray<T>.Instance; }
}
public static class EmptyArray<T>
{
public static readonly T[] Instance = new T[0];
}
@AndyPook
AndyPook / es-curator.ps1
Created March 9, 2016 13:59
very simple powershell script to delete older logstash indexes
# get indexes in "logstash" alias
$indexes = Invoke-RestMethod "http://eshost:9200/logstash/_settings"
# get the names of the indexes
$indexNames = Get-Member -InputObject $indexes -MemberType NoteProperty|%{$_.Name}
# foreach index check its age. If over 10 days, delete it
# "Substring(9)" returns the date part of "logstash-yyyy-mm-dd"
$indexNames|sort |%{
$datePart = $_.Substring(9)
@AndyPook
AndyPook / profile.ps1
Created March 9, 2016 14:40
powershell script to import VisualStudio environment variables
# Set environment variables for Visual Studio Command Prompt
# Based on: http://stackoverflow.com/questions/2124753/how-i-can-use-powershell-with-the-visual-studio-2010-command-prompt
$version=14
pushd "c:\Program Files (x86)\Microsoft Visual Studio ${version}.0\Common7\Tools"
cmd /c "vsvars32.bat&set" |
foreach {
if ($_ -match "=") {
$v = $_.split("=")
set-item -force -path "ENV:\$($v[0])" -value "$($v[1])"
}
@AndyPook
AndyPook / SemVer.cs
Last active March 29, 2016 14:31
Class to parse SemVer strings and extract version from current process
/// <summary>
/// Parses a full product version string into component parts
/// </summary>
public sealed class SemVer : IComparable<SemVer>
{
public static readonly SemVer Null = new SemVer((string)null);
public static SemVer GetFromPath(string path)
{
if (!File.Exists(path))
[Serializable]
[TypeConverter(typeof(ElasticObjectTypeConverter))]
[TypeDescriptionProvider(typeof(ElasticObjectTypeDescriptionProvider))]
public sealed class ElasticObject : DynamicObject, IDictionary<String, Object>, ICloneable, INotifyPropertyChanged
{
private static readonly String [] SpecialKeys = new String[] { "$Path", "$Parent", "$Root", "$Value", "$Type" };
private readonly IDictionary<String, Object> values = new Dictionary<String, Object>();
private Object value;
private ElasticObject parent;
@AndyPook
AndyPook / boxstarter
Last active May 11, 2017 14:32
boxstarter script
Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -EnableShowProtectedOSFiles -EnableShowFileExtensions -EnableShowFullPathInTitleBar -EnableOpenFileExplorerToQuickAccess -EnableShowRecentFilesInQuickAccess -EnableShowFrequentFoldersInQuickAccess -EnableExpandToOpenFolder
Enable-RemoteDesktop
Update-ExecutionPolicy Unrestricted -Force
Disable-InternetExplorerESC
Disable-BingSearch
cinst chocolatey
cinst Boxstarter

Keybase proof

I hereby claim:

  • I am andypook on github.
  • I am andypook (https://keybase.io/andypook) on keybase.
  • I have a public key ASDTiKH0PWmgycLyEv9erqHBwKrpqc9ap3OAUUKSmbdzRgo

To claim this, I am signing this object:

@AndyPook
AndyPook / Dockerfile
Created July 26, 2019 11:14
Docker file for docfx
FROM debian:stretch-slim
# Install system components
RUN apt-get update
RUN apt-get install -y curl apt-transport-https dirmngr gnupg ca-certificates unzip
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
# Import the public repository GPG keys
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -