Skip to content

Instantly share code, notes, and snippets.

View thenameless314159's full-sized avatar

Nameless thenameless314159

View GitHub Profile
namespace YourProject.YourForlder
{
using System;
using YourProject.Abstractions.Interfaces;
public static class MessageParser
{
public static bool TryParse(IReader reader, out int messageId, out int dataLength, out byte[] data)
{
messageId = 0;
@thenameless314159
thenameless314159 / PartsManager.cs
Created June 21, 2017 07:36
Simple predicat/method wrapper
public class PartsManager<TP, T>
where TP : AbstractPart<T>
{
private static Dictionary<TP, MethodInfo> PartMapper { get; }
static PartsManager()
{
var ass = typeof(TP).Assembly;
var types =
@thenameless314159
thenameless314159 / App.cs
Created June 25, 2017 21:50
experimental async entry point for wpf app
/// <summary>
/// Entry Point of the App
/// </summary>
public partial class App
{
private CancellationTokenSource _mainTokenSource;
private TaskScheduler _mainScheduler;
public TaskFactory MainFactory()
=> new TaskFactory(
@thenameless314159
thenameless314159 / ConsoleLogger.cs
Created June 25, 2017 22:09
Simple console color logger
/// <summary>
/// Simple console logger, this is basically a text formatter
/// </summary>
public class ConsoleLogger
{
private static Dictionary<LogType, ConsoleColor> ColorWrapper { get; }
static ConsoleLogger()
{
ColorWrapper = new Dictionary<LogType, ConsoleColor>()
@thenameless314159
thenameless314159 / LogMessage.cs
Created June 27, 2017 06:20
Simple FactoryMethod design pattern real-world example
public class LogMessage
{
public LogType LogType { get; }
public string Message { get; }
public string Source { get; }
public DateTime Timestamp { get; }
public Exception Exception { get; }
private LogMessage(LogType logType, string message, string sourceName, Exception exception = null)
{
@thenameless314159
thenameless314159 / LoggerFactory.cs
Created June 27, 2017 10:15
High performance async/sync logger factory using TPL
public class LoggerFactory
{
public ILogger Logger { get; }
public AsyncCollection<LogMessage> MessageCollection { get; }
private ILogWriter LogWriter { get; }
private CancellationTokenSource MainTokenSource { get; }
private TaskFactory DispatcherFactory()
=> new TaskFactory(
MainTokenSource.Token,
@thenameless314159
thenameless314159 / LICENSE.txt
Last active July 8, 2017 16:47
Simple predicat executor
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
@thenameless314159
thenameless314159 / DynamicMethodBuilder.cs
Created July 8, 2017 17:33
simple dynamic method builder (basic constructor)
public delegate TObj InitializerDlg();
public static Delegate GetDynamicDlg()
{
var ctor = typeof(TObj).GetTypeInfo()
.DeclaredConstructors
.First(
c => c.GetParameters().Length < 1);
var method = new DynamicMethod(
@thenameless314159
thenameless314159 / ConsoleOutputStrategy.cs
Created May 10, 2019 09:59
Astron: LoggingStrategy imlemention
/// <summary>
/// Use this strategy to output logs to your console.
/// </summary>
public class ConsoleOutputStrategy : LoggingStrategy
{
private readonly Dictionary<LogLevel, ConsoleColor> _colorWrapper = new Dictionary<LogLevel, ConsoleColor>()
{
{LogLevel.Trace, ConsoleColor.DarkGreen },
{LogLevel.Debug, ConsoleColor.Green },
{LogLevel.Info, ConsoleColor.Blue },
@thenameless314159
thenameless314159 / CustomVarInt16BinaryStorage.cs
Created May 17, 2019 13:15
Astron.Binary storage implementation for the CustomVar<short> provided on the wiki summary of Astron.
public class CustomVarInt16BinaryStorage : IBinaryStorage<CustomVar<short>>
{
public Func<IReader, CustomVar<short>> ReadValue => reader =>
{
var result = 0;
for (var offset = 0; offset < 16; offset += 7)
{
var readByte = reader.ReadValue<sbyte>();
var hasNext = (readByte & 128) == 128;