Skip to content

Instantly share code, notes, and snippets.

View ovatsus's full-sized avatar

Gustavo Guerra ovatsus

  • London, United Kingdom
View GitHub Profile
module Html =
type HtmlNode =
| HtmlElement of name:string * attribute:HtmlAttribute list
| HtmlText of content:string *parent:HtmlNode
and HtmlAttribute =
| HtmlAttribute of name:string * value:string * parent:HtmlNode
let createElement name attrs =
@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 / 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 / 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 / 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 / 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;
@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 / scriptSetup.fsx
Created September 2, 2012 12:11 — forked from nrolland/scriptSetup.fsx
Script for loading dependencies in fsx file from a solution/project
//This script generates
//a file named __project.fsx, for each proejct which can be #load "__project.fsx" in script intending to use the same dependency graph as the code in VS
//a file named __solmerged.fsx, at the solution root which can be #load "__solmerged.fsx" in script intending to use the same dependency graph as the code in VS
//In both cases, this enforce that a script compiling in VS should work from within FSI
#if INTERACTIVE
#r "System.Xml"
#r "System.Xml.Linq"
#endif
@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 / gist:5354478
Last active December 16, 2015 01:19
WorldBank API
This file has been truncated, but you can view the full file.
class WorldBankDataProvider
static member GetDataContext: () -> WorldBankDataProvider+ServiceTypes+WorldBankDataService
class WorldBankDataProvider+ServiceTypes
class WorldBankDataProvider+ServiceTypes+WorldBankDataService : FDR.WorldBank.WorldBankData
member Countries: WorldBankDataProvider+ServiceTypes+Countries with get
member Regions: WorldBankDataProvider+ServiceTypes+Regions with get
member Topics: WorldBankDataProvider+ServiceTypes+Topics with get