Skip to content

Instantly share code, notes, and snippets.

View vbfox's full-sized avatar
❄️
Winter is coming

Julien Roncaglia vbfox

❄️
Winter is coming
View GitHub Profile
@vbfox
vbfox / FSharOptionCheckExtensions.cs
Created December 17, 2014 10:54
F# Option type support for NFluent
using Microsoft.FSharp.Core;
using NFluent;
using NFluent.Extensibility;
namespace UnitTests
{
public static class FSharOptionCheckExtensions
{
public static void IsNone<T>(this ICheck<FSharpOption<T>> check)
{
@vbfox
vbfox / RedirectPost.cs
Created February 10, 2015 16:18
Nancy Self-Host to redirect completely to another domain including 307 for POST
using System;
using Nancy;
using Nancy.Hosting.Self;
using Nancy.Responses;
namespace NancyRedirect
{
public class Program : NancyModule
{
static void Main()
@vbfox
vbfox / getline.fs
Last active August 29, 2015 14:16
A line-for-line port of getline.cs by Miguel de Icaza to F#
//
// getline.fs: A command line editor
//
// Authors:
// Miguel de Icaza (miguel@novell.com)
// Julien Roncaglia (julien@roncaglia.fr)
//
// Copyright 2008 Novell, Inc.
// Copyright 2015 Julien Roncaglia <julien@roncaglia.fr>
//
@vbfox
vbfox / Queue.fs
Created March 8, 2015 13:16
Small exercise of implementing a functional queue
module Queue
// "Purely Functional Data Structures" by Chris Okasaki, Page 18 (Figure 3.2)
open System
type queue<'a> = { F : 'a list; R : 'a list }
let empty = { queue.F = []; R = [] }
let isEmpty queue = List.isEmpty queue.F
let private makeQueue = function
| ([], r) -> { F = List.rev r; R = [] }
| (f, r) -> { F = f; R = r }
@vbfox
vbfox / UrlProtocol.cs
Last active August 29, 2015 14:17
Check if URL prototocol is handled on windows
using System;
using System.IO;
using System.Security;
using Microsoft.Win32;
static class UrlProtocol
{
public static bool IsSupported(string protocol)
{
if (protocol == null) throw new ArgumentNullException("protocol");
@vbfox
vbfox / WinScpFtp.fsx
Created April 9, 2015 09:50
Use WinSCP to upload a local directory by FTP in a Fake script
#r @"../packages/WinSCP/lib/WinSCPnet.dll"
open WinSCP
open System
open System.IO
type FtpServer =
{
HostName : string
UserName : string
@vbfox
vbfox / EnumerableBatch.cs
Last active August 29, 2015 14:24
Linq IEnumerable batching
// Variant of MoreLinq Batch implementation
// https://code.google.com/p/morelinq/source/browse/MoreLinq/Batch.cs
public static IEnumerable<IEnumerable<T>> Batch<T>(IEnumerable<T> source, int size)
{
T[] bucket = null;
var count = 0;
foreach (var item in source)
{
@vbfox
vbfox / EwsExtensions.cs
Last active August 29, 2015 14:24
Utilities for Exchange Webservice
static class EwsExtensions
{
public static string GetFullPath(this Folder folder, string separator = "/")
{
var folderPathProperty = new ExtendedPropertyDefinition(26293, MapiPropertyType.String);
var folderPathPropertySet = new PropertySet(BasePropertySet.FirstClassProperties) { folderPathProperty };
var folderWithFullnameProperty = Folder.Bind(folder.Service, folder.Id, folderPathPropertySet);
object pathObj = null;
if (!folderWithFullnameProperty.TryGetProperty(folderPathProperty, out pathObj))
@vbfox
vbfox / es_shield.md
Last active August 29, 2015 14:24
Using ElasticSerarch shield to secure inter-node communications

Using ElasticSerarchshield to secure inter-node communications

All is from a cygwin console like Babun under windows.

CA certificate creation

openssl genrsa -des3 -out root-ca.key 2048
@vbfox
vbfox / SvnFixBinaryCsFiles.cs
Created November 10, 2010 10:35
LINQPad program to remove 'svn:mime-type' properties with 'application/octet-stream' value from '.cs' files.
void Main()
{
var dir = "C:\\Code\\Repo\\";
var onlyChanged = true;
if (onlyChanged)
{
Console.WriteLine("Getting files from SVN... ");
var changed = GetSvnStatus(dir)
.Where(t => t.Item1 == 'A' || t.Item1 == 'M')