Skip to content

Instantly share code, notes, and snippets.

View EifelMono's full-sized avatar

Andreas Klapperich EifelMono

View GitHub Profile
@EifelMono
EifelMono / KeepAlive.cs
Created July 8, 2014 07:20
KeepAliveExtention
public static void UseKeepAlive(this TcpClient client, ulong time = 2000, ulong interval = 500)
{
if (client == null)
return;
// "consts" to help understand calculations
const int bytesperlong = 4; // 32 / 8
const int bitsperbyte = 8;
try
{
@EifelMono
EifelMono / InvokeOnMainThread.cs
Last active August 29, 2015 14:04
InvokeOnMainThread for WPF and Forms
// For WPF you need the following Assemblies
// PresentationCore
// PresentationFramework
// WindowsBase
// WindowsFormsIntegration
// For Forms
// System.Windows.Forms
// create this in the main thread for your Forms application
internal static Control MainThreadInvokerControl;
@EifelMono
EifelMono / In.cs
Created August 5, 2014 05:39
c# Extentions In
public static class Extentions
{
public static bool In<T>(this T value, params T[] args) where T : IComparable
{
foreach (T arg in args)
if (arg.Equals(value))
return true;
return false;
}
@EifelMono
EifelMono / IsAssigned.cs
Created August 7, 2014 05:43
c# Extention IsAssigned
public static class Extentions
{
public static bool IsAssigned(this object value)
{
return value != null;
}
}
@EifelMono
EifelMono / CommandHandler.cs
Last active August 29, 2015 14:07
WPF CommandHandler
// Command xCommand = new CommandHandler(() => DoX());
class CommandHandler : ICommand
{
private Action m_Action;
public CommandHandler(Action action)
{
@EifelMono
EifelMono / Asp.Net.Core Swagger (Swashbuckle) Startup.cs
Last active July 19, 2017 13:06
Swagger (Swashbuckle) Startup in Asp.Net Core with Xml documentation!
// http://x.x.x.x:port/swagger/ui/index.html
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
@EifelMono
EifelMono / Where are the Nuget packages on Visual Studio 2017.txt
Last active May 15, 2017 20:35
Where are the Nuget packages on Visual Studio 2017
Windows C:\Users\[YourUsername]\.nuget\packages
macOS /Users/[YourUsername]/.nuget/packages
@EifelMono
EifelMono / Tasks.Extensions.cs
Created June 1, 2017 06:01
Tasks.Extensions.cs
public static class TasksExtensions
{
public static Task AsTask(this CancellationTokenSource cancellationTokenSource)
{
return Task.Delay(-1, cancellationTokenSource.Token);
}
}
@EifelMono
EifelMono / CancellationTokenSource.AsTask().cs
Last active December 9, 2017 17:03
Task.WhenAny(Task1, Task2, ....., CancellationTokenSource1.AsTask())
public static class TasksExtensions
{
public static Task AsTask(this CancellationTokenSource cancellationTokenSource, int delay= -1)
{
return Task.Delay(delay, cancellationTokenSource.Token);
}
}
@EifelMono
EifelMono / .gitignore(cake)
Created December 9, 2017 17:03
cake to ignore in .gitignore
# cake.build
**/tools/**
!**/tools/packages.config
tools/**
!tools/packages.config