Skip to content

Instantly share code, notes, and snippets.

@bronumski
bronumski / TcpPort.cs
Last active August 5, 2020 21:11
Gets the next available port number
public static class TcpPort
{
public static int NextFreePort()
{
var l = new TcpListener(IPAddress.Loopback, 0);
try
{
l.Start();
return ((IPEndPoint)l.LocalEndpoint).Port;
public static class Deserialize
{
public static TResponse Deserialize<TResponse>(string xmlString)
{
var serializer = new XmlSerializer(typeof(TResponse));
using (var stringReader = new StringReader(xmlString))
{
return (TResponse)serializer.Deserialize(stringReader);
}
}
@bronumski
bronumski / .ReadMe
Last active December 20, 2015 11:09
Roman numeral parser
Roman numerals
--------------
http://en.wikipedia.org/wiki/Roman_numerals
Reading Roman numerals
----------------------
Based on seven symbols
I = 1
@bronumski
bronumski / YoutrackImport.fsx
Last active December 30, 2015 03:59
FSharp script to import into YouTrack from a CSV file
module Constants =
[<Literal>]
let ImportDataFileUrl = "Data.csv"
let YouTrackUrl = "http://LocalHost:8082"
let YouTrackAdminUserName = "root"
let YouTrackAdminPassword = "password"
let YouTrackProjectID = "PROJ"
#r "FSharp.Data.1.1.10/lib/net40/FSharp.Data.dll"
#r "RestSharp.104.4.0/lib/net4/RestSharp.dll"
@bronumski
bronumski / RelayCommand.cs
Created June 12, 2014 09:58
WPF Relay command
public class RelayCommand<T> : ICommand
{
private readonly Predicate<T> canExecute;
private readonly Action<T> execute;
public RelayCommand(Action<T> action)
: this(x => true, action)
{
execute = action;
}
@bronumski
bronumski / UriManager.cs
Created June 19, 2014 11:25
Creates or gets a uri for a service or unique name with a random free port.
static class UriManager
{
private static readonly IDictionary<string, Uri> Uris = new Dictionary<string, Uri>();
public static Uri GetUriForService<TService>()
{
return GetUri(typeof (TService).Name);
}
public static Uri GetUri(string serviceName)
@bronumski
bronumski / Publisher.cs
Created September 23, 2014 15:35
RabbitMQ Demo
using System;
using System.Text;
using RabbitMQ.Client;
namespace Publisher
{
class Program
{
static void Main(string[] args)
{
@bronumski
bronumski / GenericConverter.cs
Created December 10, 2014 18:52
Basic idea on how to look up a type converter based on a generic type and convert to that value from a string
public TValue Value<TValue>(string value, TValue defaultValue = default(TValue))
{
if (string.IsNullOrEmpty(value)) return defaultValue;
var converter = TypeDescriptor.GetConverter(typeof (TValue));
return (TValue) converter.ConvertFrom(value);
}
@bronumski
bronumski / GetAssemblyFileVersion.cs
Created January 8, 2015 19:36
Get Assembly File Version
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fvi.FileVersion;
class HttpApiGuidlinesMiddleware : OwinMiddleware
{
public HttpApiGuidlinesMiddleware(OwinMiddleware next) : base(next) { }
public override async Task Invoke(IOwinContext context)
{
var isApiCall = context.Request.Path.StartsWithSegments(new PathString("/api"));
Stream originalStream = null;
Stream responseBuffer = null;