Skip to content

Instantly share code, notes, and snippets.

@Yoshi662
Yoshi662 / ApiResult.cs
Created March 9, 2026 12:07
My best take to the operation result pattern in C#, but oriented to their use in RESTApis
public static class ApiResultUsageExample
{
public static ApiResult Result_OK() => new();
public static ApiResult Result_KO()
{
return new ApiError("Validation Error", HttpStatusCode.BadRequest);
}
public static ApiResult Result_KO2()
{
@Yoshi662
Yoshi662 / Result.cs
Last active March 9, 2026 12:04
My best take to the operation result pattern in C#.
public static class ResultUsageExample
{
public static Result Result_OK() => new();
public static Result Result_KO()
{
return new Error("Something Went Wrong");
}
public static Result Result_KO2()
{
@Yoshi662
Yoshi662 / Pingu.cs
Last active April 30, 2022 23:05
An easy way in .NET 6.0 to ping servers!
//Extra info at the end of the file
using Pingu;
using System.Net.NetworkInformation;
using System.Text.Json;
//Actually using <https://github.com/Yoshi662/Logger>
string serversfile = @"servers.json",
logconfigfile = @"logconfig.json";
int timeBetweenPings = 2000;
@Yoshi662
Yoshi662 / ExceptionWriter.cs
Created January 10, 2022 09:43
A super easy way to have exceptions written in files
public static void WriteLog(Exception ex)
{
if (!Directory.Exists("Exceptions"))
Directory.CreateDirectory("Exceptions");
string errorMessage =
$"{ex.GetType().Name} - {DateTime.Now:u}" +
$"\n{ex.Message}" +
$"\n\n{ex.StackTrace}";
@Yoshi662
Yoshi662 / Progressbar.cs
Created November 29, 2021 08:52
An easy way to generate a text based progress bar
public static class Utils
{
const int PB_MAX_SIZE = 30; //Change at will
/// <summary>
/// Generates a Text Based Progress bar
/// </summary>
/// <param name="percentage">Percentage of progress</param>
/// <param name="max_size">Max Width in characters of the progress bar</param>
/// <returns>A progress bar EX: ▰▱▱▱▱▱▱▱▱▱▱▱▱▱▱▱▱▱ - [10,00 %]</returns>
@Yoshi662
Yoshi662 / SimpleSingleton.cs
Created November 29, 2021 08:50
A simple Singleton pattern example class written in C#
public class SimpleSingleton
{
private static SimpleSingleton _instance;
private SimpleSingleton()
{
//Constructor
}
public static SimpleSingleton Instance
@Yoshi662
Yoshi662 / Logger.cs
Last active April 30, 2022 23:05
Simple logger written in C#
//SEE MORE VERSIONS AT <https://github.com/Yoshi662/Logger>
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LoggerExample
@Yoshi662
Yoshi662 / Server_rules.md
Last active July 24, 2021 23:14
A set of rules for a certain discord language exchange server

0 - Respect

We don’t tolerate:

  • Trolling, harassment, doxing, witch hunting, racism, hate speech, disruptive behavior.
  • Discriminatory jokes against someone’s race, age, gender, sexual orientation, etc.

1 - Spam

  • Self-advertisement, flooding, excessive use of links, walls of text, emojis, server invites, mentions, epilepsy triggering content, etc.

2 - Content

  • No NSFW content: pictures, gifs, or detailed descriptions (This includes your own nickname/alias, profile picture, and status).