Skip to content

Instantly share code, notes, and snippets.

View rflechner's full-sized avatar

Flechner Romain rflechner

View GitHub Profile
@rflechner
rflechner / SuaveSwaggerSample.fsx
Last active April 1, 2017 10:06
Example of Suave.Swagger using in a Sample script
(*
In your shell
$ paket init
$ paket add nuget suave.swagger
$ paket install
$ paket generate-include-scripts
$ code .
*)
#load ".paket/load/main.group.fsx"
@rflechner
rflechner / UsersController.cs
Last active January 20, 2017 12:01
MVC validation exemple
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq;
using System.Net;
using System.Web.Mvc;
using Newtonsoft.Json;
namespace WebApplication1.Controllers
{
// It a DTO model
@rflechner
rflechner / EventStoreService.cs
Created December 20, 2016 15:41 — forked from trbngr/EventStoreService.cs
EventStore as a windows service w/ TopShelf
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
namespace EventStoreService
{
public class EventStoreService
{
@rflechner
rflechner / HttpUriEncode.fs
Last active December 9, 2016 14:32
Encode and decode url algorithm
let toHex (c:char) = Convert.ToInt32(c) |> fun i -> i.ToString("X")
let encode s =
let parts = s |> Seq.map (fun c -> "%" + (c |> toHex))
String.Join("", parts)
let (|HexaChar|_|) (s:char list) =
if s.Length > 0 && s.Head = '%' then
let chars = s |> Seq.skip 1 |> Seq.take 2 |> Array.ofSeq
let h = new String(chars)
let num = Convert.ToInt32(h, 16)
#I @"packages\Selenium.WebDriver\lib\net40"
#I @"packages\canopy\lib"
#I @"packages\FAKE\tools\"
#r "FakeLib.dll"
#r "canopy.dll"
#r "WebDriver.dll"
open System
open System.IO
@rflechner
rflechner / Fibonacci.fsx
Last active September 28, 2017 12:27
3 implementations of fibonacci in FSharp
// recursive
let rec fiboRec =
function
| 0L -> 0L
| 1L -> 1L
| n -> fiboRec (n-1L) + fiboRec (n-2L)
#time
@rflechner
rflechner / CSS_selector_parsing_exercice.fsx
Last active November 18, 2016 08:56
CSS selector parsing exercice
open System
module Domain =
type ClassName = string
type TagName = string
type HtmlId = string
type Token =
| TagSelector of TagName
| ClassSelector of ClassName
| WhiteSpace
@rflechner
rflechner / Dichotomy.csx
Last active November 10, 2016 09:38
Testing Dichotomy
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
static int SearchWithDichotomy(IList<int> nums, int target)
{
var min = 0;
var max = nums.Count;
@rflechner
rflechner / Get-CsharpFileNotEndingWithLF.ps1
Last active October 20, 2016 14:17
Get C# files not ending with LF (\n)
Function Get-CsharpFileNotEndingWithLF([string]$path)
{
$files = Get-ChildItem -Path $path -Recurse -Include @("*.cs")
$files | Foreach {
$content = [System.IO.File]::ReadAllText($_)
if ($content -ne $null)
{
$endsWithCRLF = $content.EndsWith("`n")
if (-not $endsWithCRLF -and -not $_.FullName.Contains("\obj\")) {
@rflechner
rflechner / MSDeployHelper.fs
Last active October 5, 2016 19:59
MSDeploy module for FAKE
open Fake
open ProcessHelper
open System
open System.IO
module MSDeployHelper =
type MSDeployPackageParams =
{ ProjectDir:string
PackageFullPath:string
Timeout:TimeSpan }