Skip to content

Instantly share code, notes, and snippets.

@mavnn
mavnn / nasty.fs
Created June 6, 2013 11:19
Don't try this at home! NuGet will hurt your brain.
let RemoveFilesFromProj packageInstallPath (package : IPackage) (project : IProjectSystem) (localRepo : IPackageRepository) =
let packagesConfig = "packages.config"
let otherPackages =
(XDocument.Parse <| project.OpenFile(packagesConfig).ReadToEnd())
.Descendants(XName.Get "package")
|> Seq.filter (fun p -> p.Attribute(XName.Get "id").Value <> package.Id)
|> Seq.map (fun p -> localRepo.FindPackage(p.Attribute(XName.Get "id").Value, new SemanticVersion(p.Attribute(XName.Get "version").Value), true, true))
let inUseByOtherPackages =
otherPackages
|> Seq.map (fun p -> getFiles project p)
@mavnn
mavnn / Did work.fs
Last active December 19, 2015 08:29
Fantomas test cases - notice brackets around the tuple deconstruction. The error only seems to occur once the tuple splits between two lines.
let (assemblyReferencesToDelete, frameworkReferencesToDelete, contentFilesToDelete, buildFilesToDelete) =
let assemblyReferencesToDelete, frameworkReferencesToDelete, contentFilesToDelete, buildFilesToDelete =
1, 2, 3, 4
1, 2, 3, 4
@mavnn
mavnn / XmlGen.fs
Last active September 2, 2016 17:03
Really naive xml generator for FsCheck.
open FsCheck
type XmlTree =
| NodeName of string
| Container of string * List<XmlTree>
let nodeNames = ["myNode";"myOtherNode";"someDifferentNode"]
let tree =
let rec tree' s =
#r "System.Xml.Linq"
#r "tools\FAKE\FakeLib.dll"
open System.IO
open System.Xml
open System.Xml.Linq
open System.Xml.XPath
open Fake
// You'll want to replace these values...
let nugetId = "my.package.id"
module DevEd.FsCheck
open System.Xml
open System.Xml.Linq
let AddEnhancement (xDoc : XDocument) (input : string) =
xDoc.Root.Add(XElement(XName.Get "Enhancement", input))
xDoc
@mavnn
mavnn / Test.fs
Created August 8, 2013 13:20
Add a dll directory from which to DllImport native code.
open System
open System.Runtime.InteropServices
open System.ComponentModel
[<DllImport("kernel32")>]
extern int AddDllDirectory(string NewDirectory)
[<EntryPoint>]
let main argv =
let result = AddDllDirectory("c:\\")
@mavnn
mavnn / csharp.cs
Created September 24, 2013 13:17
C# and F# comparisons of NuGet ProjectSystem implementations. F# code is from https://github.com/mavnn/NuGetPlus/blob/master/NuGetPlus.Core/ProjectSystem.fs C# code is from http://nuget.codeplex.com/SourceControl/latest#src/CommandLine/Common/MSBuildProjectSystem.cs They aren't identical in functionality, but they're pretty similar and implement…
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Versioning;
using Microsoft.Build.Evaluation;
namespace NuGet.Common
{
@mavnn
mavnn / part1.fs
Created October 14, 2013 09:55
Introducing F# Syntax
// Let's send an email!
let ones =
seq {
while true do
yield 1
}
// seq [1; 1; 1; 1; ...]
@mavnn
mavnn / riemannlogs.fs
Created November 7, 2013 11:28
Pipe logs to Riemann
module RiemannStore =
open System
open System.Configuration
open Riemann
let client = new Client(riemannServer, riemannPort)
let state entry =
match entry.Level with