Skip to content

Instantly share code, notes, and snippets.

View ovatsus's full-sized avatar

Gustavo Guerra ovatsus

  • London, United Kingdom
View GitHub Profile
@ovatsus
ovatsus / Setup.fsx
Created March 17, 2012 17:07
Script to setup F# Interactive session, loading everything in the current solution
#r "System.Xml.Linq"
open System
open System.IO
open System.Xml.Linq
let script = seq {
//TODO: this currently loads fsproj's in alphabeticall order, we should instead
//build the dependencies graph of the fsproj's and load them in topological sort order
@ovatsus
ovatsus / gist:1608951
Last active October 20, 2015 11:46
Serialization of Dictionary<string, object>
using System.Collections.Generic;
using Newtonsoft.Json;
using NUnit.Framework;
using ServiceStack.Text;
using JsonSerializer = ServiceStack.Text.JsonSerializer;
namespace Tests
{
[TestFixture]
public class TestJsonSerialization
@ovatsus
ovatsus / ChartExtensions.fs
Created October 22, 2011 12:04
FSharpChart extensions
[<AutoOpen>]
module ChartExtensions
open System.Drawing
open System.Windows.Forms.DataVisualization.Charting
open MSDN.FSharp.Charting
open MSDN.FSharp.Charting.ChartTypes
type SeriesProperties with
@ovatsus
ovatsus / XElementReader.cs
Created September 19, 2011 01:08
Streaming XML input with XElementReader
using System;
using System.Collections.Generic;
using System.IO;
#if XML_DEBUG_MODE
using System.Linq;
#endif
using System.Xml;
using System.Xml.Linq;
public class XElementReader : IDisposable {
@ovatsus
ovatsus / DoubleStaticStringDictionary.cs
Created September 19, 2011 01:06
DoubleStaticStringDictionary
using System;
using System.Collections.Generic;
public static class DoubleStaticStringDictionary {
public static DoubleStaticStringDictionary<Type> Create<Type>(IEnumerable<KeyValuePair<string, Type>> dict, Func<string, Type> fallback, Func<Type, string> reverseFallback) {
return new DoubleStaticStringDictionary<Type>(dict, fallback, reverseFallback);
}
}
@ovatsus
ovatsus / StaticStringDictionary.cs
Created September 19, 2011 01:06
StaticStringDictionary
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
public static class StaticStringDictionary {
public static StaticStringDictionary<Type> Create<Type>(IEnumerable<KeyValuePair<string, Type>> dict, Func<string, Type> fallback) {
@ovatsus
ovatsus / MSMQCountSafe.cs
Created September 19, 2011 01:03
Counting the number of messages in a Message Queue in .NET - safe version
using System;
using System.Messaging;
using System.Runtime.InteropServices;
public static class MessageQueueExtensions {
[DllImport("mqrt.dll")]
private static extern int MQMgmtGetInfo([MarshalAs(UnmanagedType.BStr)]string computerName, [MarshalAs(UnmanagedType.BStr)]string objectName, ref MQMGMTPROPS mgmtProps);
private const byte VT_NULL = 1;
@ovatsus
ovatsus / MSMQCountUnsafe.cs
Created September 19, 2011 01:02
Counting the number of messages in a Message Queue in .NET - unsafe version
using System;
using System.Messaging;
using System.Runtime.InteropServices;
static class MessageQueueExtensions {
[DllImport("mqrt.dll")]
private unsafe static extern int MQMgmtGetInfo(char* computerName, char* objectName, MQMGMTPROPS* mgmtProps);
private const byte VT_NULL = 1;