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
@gsscoder
gsscoder / SimpleCmdLineApp.vb
Last active November 7, 2019 14:16
Simple Command Line Parser Library Console Application
' needs CommandLine.dll prior to 1.9.4.91
' for later versions: templates are up to date
Imports CommandLine
Imports CommandLine.Text
Imports System.Reflection
<Assembly: [AssemblyInformationalVersion]("1.0.0.0")>
Friend Class ThisAssembly
Friend Shared Title As String = "VBNetTemplate"
Friend Shared Author As String = "Your Name Here"
Friend Shared Copyright As String = "Copyright (C) 2012 " + Author
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.ComponentModel.Composition;
using System.Threading.Tasks;
using AppFunc = System.Func< // Call
System.Collections.Generic.IDictionary<string, object>, // Environment
System.Threading.Tasks.Task>; // Done
@gsscoder
gsscoder / SurfSample1.cs
Last active November 7, 2019 14:15
Super-Simple HTTP Server, demonstrates use of https://github.com/gsscoder/surfhttp (work in progress)
/*
* Toy HTTP Sample Server
* Giacomo Stelluti Scala (gsscoder@gmail.com)
* Demonstrates use of https://github.com/gsscoder/surfhttp (work in progress).
* How to execute: Copy & paste, then add a reference to Surf.dll.
*/
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
@gsscoder
gsscoder / PeekableStream.cs
Last active November 7, 2019 14:15
Peekable readonly .NET/C# stream, implemented for https://github.com/gsscoder/httphelpers
// PeekableReader is better -> https://gist.github.com/gsscoder/4945440
sealed class PeekableStream : Stream
{
public PeekableStream(Stream stream)
{
_stream = stream;
_peeked = new byte[16];
_peekedLength = 0;
}
@gsscoder
gsscoder / PeekableReader.cs
Last active November 7, 2019 14:14
Peekable stream reader for .NET/C#
// better than PeekableStream: less code, less bugs
sealed class PeekableReader : IDisposable
{
public PeekableReader(Stream stream)
{
_stream = stream;
_byte = _stream.ReadByte();
}
public int ReadByte()
@gsscoder
gsscoder / HttpHelpersDemo1.cs
Last active November 7, 2019 14:14
Super-Simple HTTP Server, demonstrates use of https://github.com/gsscoder/httphelpers (work in progress)
/*
* Easy HTTP Sample Server
* Version 0.0.0.6 (based on HttpHelpers 0.1.5.0-alfa)
* Giacomo Stelluti Scala (gsscoder@gmail.com)
* Demonstrates use of https://github.com/gsscoder/httphelpers (work in progress)
* How to execute: Copy & paste, then add a reference to HttpHelpers.dll
* It handles two url:
* (1) http://localhost:8899/hello -> point browser & refresh
* (2) everything helse
*/
@gsscoder
gsscoder / ReadOnlyDictionary.cs
Last active November 7, 2019 14:14
Generic ReadOnlyDictionary implemented in C#, for .NET < Version 4.5
class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>
{
internal class KeyCollection : ICollection<TKey>
{
public KeyCollection(ICollection<TKey> collection)
{
if (collection == null) { throw new ArgumentNullException("collection"); }
_collection = collection;
}
@gsscoder
gsscoder / CSharp_Partial_Implementation.cs
Created February 14, 2013 19:22
C# wish list: Partial Implementation of Interfaces
/*
for C# wish list
----------------
partial implementation of interface while coding
(something can be done with DynamicMethod, IL generation
but I'd like a language feature)
*/
interface IMyInterface {
@gsscoder
gsscoder / SimpleOwinApp_on_OwinHttpListener.cs
Last active November 7, 2019 14:12
Snippet that demonstrate how to run SimpleOwinApp (https://github.com/gsscoder/simpleowinapp) with Owin Http Listener (https://github.com/gsscoder/owinhttplistener)
var listener = new OwinHttpListener(
new WebApp().PrintRequest,
new IPAddress(new byte[] { 0, 0, 0, 0 }), 8899);
listener.Start();
listener.ListenAsync().Wait();
Console.ReadKey();
@gsscoder
gsscoder / FireflyHostingNancy.cs
Last active November 7, 2019 14:12
Firefly hosting NancyFx
/*
* Install-Package Firefly
* Install-Package Nancy
* Install-Package Nancy.Owin (or just this, will pull the former)
*/
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using Firefly.Http;