Skip to content

Instantly share code, notes, and snippets.

View ArisAgnew's full-sized avatar
:electron:
You gotta do what you gotta do

Εὐγενής Αναγνωστόπουλος ArisAgnew

:electron:
You gotta do what you gotta do
  • Europe
View GitHub Profile
@ArisAgnew
ArisAgnew / WriteAsync.cs
Created February 12, 2022 11:57
The code snippet is a gauge of writing a piece of information to a file in an asynchronous way
Task.Run(ProcessWriteAsync); // main function call
async Task ProcessWriteAsync()
{
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string subPath = @"logs\";
string fileName = $@"chatlogs.txt";
DirectoryInfo directoryInfo = new(baseDirectory);
@ArisAgnew
ArisAgnew / Program.cs
Created November 27, 2021 13:27 — forked from DanielSWolf/Program.cs
Console progress bar. Code is under the MIT License: http://opensource.org/licenses/MIT
using System;
using System.Threading;
static class Program {
static void Main() {
Console.Write("Performing some task... ");
using (var progress = new ProgressBar()) {
for (int i = 0; i <= 100; i++) {
progress.Report((double) i / 100);
@ArisAgnew
ArisAgnew / Table-DrivenApproach.cs
Created June 20, 2021 20:01
Refactoring If-Else to Table-Driven Approach
//If-Else Approach
public static class ParserFactory
{
public static IFileParser Create(string filename)
{
var extension = Path.GetExtension(fileName);
if (extension == ".json")
{
return new JsonParser();
@ArisAgnew
ArisAgnew / StateDesignPattern.cs
Created June 20, 2021 19:58
Refactoring If-Else to State Design Pattern
//If-Else Approach
public enum Reaction
{
Initial = 1,
Liked = 2,
Disliked = 3
}
public class LikeDislikeComponent
{
@ArisAgnew
ArisAgnew / ValueObjectApproach.cs
Last active June 20, 2021 19:55
Refactoring If-Else to Value Object
//If-Else Approach
public class User
{
public string Name { get; set; }
public string Email { get; set; }
public void ChangeEmail(string email)
{
if (!IsEmailValid(email))
throw new ArgumentException("{email} is not valid.", email);
@ArisAgnew
ArisAgnew / FibonacciExtended.cs
Created May 11, 2021 10:21
FibonacciInterfaceIterator.cs
public interface IReader<T> where T : notnull
{
IReadOnlyCollection<T> GetElements();
T GetElementAt(int index) => GetElements().ElementAtOrDefault(index);
}
public record FibonacciReader : IReader<int>
{
public IReadOnlyCollection<int> GetElements() => new FibonacciSequence().ToList();
}
@ArisAgnew
ArisAgnew / EqualsExampleToRight.cs
Created April 4, 2021 11:27
EqualsExampleToRight
public Rect(decimal x, decimal y, decimal width, decimal height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
/// <summary>
/// The x coordinate of the element in pixels.
@ArisAgnew
ArisAgnew / Fibonacci.cs
Last active March 10, 2021 10:42
Fibonacci IEnumerable C#
static void Main()
{
foreach (var num in Fibonacci(7))
{
Console.WriteLine(num);
}
}
protected static IEnumerable<uint> Fibonacci(uint number)
{
@ArisAgnew
ArisAgnew / TierHandler.cs
Last active October 8, 2020 11:29
Invariance, Contravariance, Covariance C#
internal class HightTier { }
internal class MediumTier : HightTier { }
internal class LowTier : MediumTier { }
internal delegate Covariance TierHandler<Invariance, in Contravariance, out Covariance>(Contravariance arg);
/// <summary>
/// if 1st_op = 2nd_op
/// then
/// <in> is tantamount to Going UP (emerged from MediumTier to HightTier)
@ArisAgnew
ArisAgnew / AmplifiedFunctionsLab.cs
Last active September 11, 2020 10:27
Basic four amplified types (classes) are defined to enhance sporadic delegates before being executed.
<PropertyGroup>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
public class AmplifiedAction
{
private Action _action;