Skip to content

Instantly share code, notes, and snippets.

@mavnn
mavnn / DynamicEntityExtensions.cs
Created May 28, 2011 13:27
Sanity inducing extensions for Dynamics CRM 4.0
public static class DynamicEntityExtensions
{
public static string GetString(this DynamicEntity entity, string property)
{
if (entity.Properties.Contains(property))
return (string)entity[property];
else
return null;
}
@mavnn
mavnn / RegenerateWSDL.fs
Created February 13, 2012 10:41
F# WSDL regeneration
open System.IO
open System.Text.RegularExpressions
open System.Diagnostics
let (|Match|_|) pattern input =
let m = Regex.Match(input, pattern)
if m.Success then Some (List.tail [for g in m.Groups -> g.Value]) else None
let abcDeploy = @"\\cvsw90163\c$\Apps\ABC2\apache-tomcat-6.0.33\webapps\ABC"
let svc = @"c:\Program Files\Microsoft SDKs\Windows\v7.0a\bin\SvcUtil.exe"
@mavnn
mavnn / get-abc.pl
Created February 13, 2012 10:42
Perl WSDL Regeneration
#!/usr/bin/perl
use strict;
use Data::Dumper;
use File::Find;
my $abc_deploy = '\\\\cvsw90163\\c$\\Apps\\ABC2\\apache-tomcat-6.0.18\\webapps\\ABC';
my $svc_util = 'C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\SvcUtil.exe';
my @files = ();
@mavnn
mavnn / Program.fs
Created November 1, 2012 12:04
EasyNetQ on F#
module Program
open EasyNetQ
type MyMessage = { Message : string }
let bus = RabbitHutch.CreateBus("host=192.168.56.1")
bus.Subscribe<MyMessage>("FSharpTest", fun mesg -> printfn "%A" mesg.Message)
bus.Publish({ Message = "Hello world"})
@mavnn
mavnn / build.fsx
Last active November 28, 2016 15:27
Literate build.fsx
(**
## References
As they aren't part of a project, fsx files need
to reference all of their dependencies within the
file.
You'll always want to reference FakeLib. VersionUpdater
is an inhouse tool we use for handling feature branch
@mavnn
mavnn / throttledParallel.fs
Created February 15, 2013 15:27
Throttled parallel execution.
open System.Collections.Concurrent
type JobRequest<'T> =
{
Id : int
WorkItem : 'T
}
type WorkRequest<'T> =
| Job of JobRequest<'T>
@mavnn
mavnn / NotAGoodIdea.fs
Created February 15, 2013 15:30
Don't do this
let inline doParallelWithThrottle limit f items =
use sem = new System.Threading.Semaphore(limit, limit)
items
|> Seq.map (fun element -> async {
sem.WaitOne() |> ignore
let result = Async.RunSynchronously <| async { return f element }
sem.Release() |> ignore
return result
})
|> Async.Parallel
@mavnn
mavnn / pathDiff.fs
Last active December 14, 2015 15:39
Fun with relative directories...
let GetHintPath hintPathFromRoot root projFile =
let rootDir = DirectoryInfo(root)
let projDir = DirectoryInfo(Path.GetDirectoryName(projFile))
let rec dirDiff (rootDir : DirectoryInfo) (currentDir : DirectoryInfo) levels =
if rootDir.FullName = currentDir.FullName then
levels
else
dirDiff rootDir (currentDir.Parent) (levels + 1)
hintPathFromRoot::[for _ in 1..(dirDiff rootDir projDir 0) -> ".."]
|> List.rev
@mavnn
mavnn / Program.fs
Created May 15, 2013 14:27
UnionArgParser - making your console apps a thing of beauty
open System
open NuGet
open ReferenceManagement
open UnionArgParser
type Argument =
| [<MandatoryAttribute>] Action of string
| [<MandatoryAttribute>] ProjectFile of string
| [<MandatoryAttribute>] PackageId of string
| Version of string
with
@mavnn
mavnn / duck.fs
Last active December 18, 2015 00:48
DuckTyping in F#
type DeliveryResult =
| Success of SuccessfulDelivery
| Bounce of Bounce
let TopicTest = Regex(@"Some relevant regex here", RegexOptions.Compiled)
let inline TryExtractTopic record =
let envId = ( ^a : (member EnvId : string) record)
match TopicTest.IsMatch(envId) with