Skip to content

Instantly share code, notes, and snippets.

View gsscoder's full-sized avatar
💭
obsessive coding disorder

coder (π³) gsscoder

💭
obsessive coding disorder
View GitHub Profile
namespace OwinHttpListenerWithNancyFx
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Nancy;
using Owin.Listener;
@gsscoder
gsscoder / cmdline_test.fs
Last active November 7, 2019 14:11
Just a snippet of test wrote against an unreleased branch of CommandLine
open System
open System.Reflection
open CommandLine
open CommandLine.Text
[<assembly: AssemblyCopyright("Copyright (c) 2013 Giacomo Stelluti Scala playing with FSharp")>]
do()
type options() =
[<Option(HelpText = "Let your program talk a lot.")>]
@gsscoder
gsscoder / Pairwise.cs
Last active December 15, 2015 04:19
IEnumerable<T>::Pairwise extension method for C# modeled like an overload of F# Seq.pairwise<'T> (http://msdn.microsoft.com/it-it/library/ee370361.aspx).
public static IEnumerable<TResult> Pairwise<TSource, TResult>(this IEnumerable<TSource> source, Func<TSource, TSource, TResult> selector)
{
if (source == null)
{
throw new ArgumentNullException("source");
}
if (selector == null)
{
throw new ArgumentNullException("selector");
@gsscoder
gsscoder / DynamicComparer.cs
Last active November 7, 2019 14:11
Invokes Enumerable::SequenceEqual generic extension method with reflection
static class DynamicComparer
{
public static bool DynamicEquals<T>(this T value, T other)
{
if (object.Equals(value, default(T)))
{
throw new ArgumentNullException("value");
}
if (object.Equals(other, default(T)))
@gsscoder
gsscoder / Option-Monad.cs
Last active November 7, 2019 14:13
C# implementation of F# option<'a> monad (this is the one used in upcoming CommandLine 2.0, so I've used Haskell naming)
internal enum MaybeType { Just, Nothing }
/// <summary>
/// C# implementation of F# 'T option. Based on the one found in http://goo.gl/jMwzg.
/// Here Haskell naming is used, to not create confusion with local option concept.
/// </summary>
internal abstract class Maybe<T>
{
private readonly MaybeType tag;
@gsscoder
gsscoder / process_darwin.go
Last active November 7, 2019 14:10
From github.com/gsscoder/goproc as in commit 13a38b6100
// Copyright 2015 Giacomo Stelluti Scala. All rights reserved. See doc/License.md in the project root for license information.
package process
/*
#include <stdlib.h>
#include "libproc.h"
*/
import "C"
import "unsafe"
@gsscoder
gsscoder / process_darwin-2.go
Last active June 4, 2023 18:59
From github.com/gsscoder/goproc as in commit 998e482ecd
// Copyright 2015 Giacomo Stelluti Scala. All rights reserved. See doc/License.md in the project root for license information.
package process
/*
#include <stdlib.h>
#include "libproc.h"
*/
import "C"
import "unsafe"
#!/bin/sh -x
#This script removes Mono from an OS X System. It must be run as root
rm -r /Library/Frameworks/Mono.framework
rm -r /Library/Receipts/MonoFramework-*
for dir in /usr/bin /usr/share/man/man1 /usr/share/man/man3 /usr/share/man/man5; do
(cd ${dir};
@gsscoder
gsscoder / AssemblyInfo.fs
Created June 18, 2015 10:42
commandline20x-pre_assemblyinfo.fs
(*
* Minimal AssemblyInfo.fs for automatic help screen generation in Command Line Parser Library 2.0.x-pre.
*)
module YourProject.AssemblyInfo
open System.Reflection
[<assembly: AssemblyCopyright("Copyright (c) 2015 Your Name Here")>]
do()
@gsscoder
gsscoder / FuncHelper.cs
Created July 16, 2015 16:23
C# Partial application and Currying
#region Partial application and Currying
static class FuncHelper
{
public static Func<T2, T3, T4, TResult> ApplyPartial<T1, T2, T3, T4, TResult>
(Func<T1, T2, T3, T4, TResult> function, T1 arg1)
{
return (b, c, d) => function(arg1, b, c, d);
}
public static Func<T2, T3, TResult> ApplyPartial<T1, T2, T3, TResult>