Skip to content

Instantly share code, notes, and snippets.

View light-traveller's full-sized avatar

light-traveller light-traveller

View GitHub Profile
@light-traveller
light-traveller / ValueObject.cs
Created November 7, 2023 17:18
DDD ValueObject
public abstract class ValueObject
{
protected abstract IEnumerable<object> GetEqualityComponents();
public override bool Equals(object? other)
{
if (other is null || other.GetType() != GetType())
{
return false;
}
@light-traveller
light-traveller / HashCode.cs
Created November 7, 2023 11:12
Old Hashcode Computation
public override int GetHashCode()
{
unchecked
{
int hash = 17;
hash = hash * 31 + firstField.GetHashCode();
hash = hash * 31 + secondField.GetHashCode();
return hash;
}
}
/*
Nuget packages: Serilog, Serilog.AspNetCore, Serilog.Sinks.Console, Serilog.Sinks.File
*/
{
"Serilog": {
"Using": ["Serilog.Sinks.Console", "Serilog.Sinks.File"],
"MinimumLevel": {
"Default": "Information",
"Override": {
/*
1. Make sure you have the Transparency Effects enabled in Windows.
2. Make sure you're not running on the battery saver mode.
From https://zimmergren.net/enable-transparent-background-in-windows-terminal/
*/
// Open settings.json (ctrl+,)
// cropped...
@light-traveller
light-traveller / Enumeration.cs
Created January 24, 2021 04:16 — forked from spewu/Enumeration.cs
Better enums in C# for DDD ... based on Jimmy Bogards Enumeration class
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
[Serializable]
[DebuggerDisplay("{DisplayName} - {Value}")]
public abstract class Enumeration<TEnumeration, TValue> : IComparable<TEnumeration>, IEquatable<TEnumeration>
where TEnumeration : Enumeration<TEnumeration, TValue>
where TValue : IComparable
@light-traveller
light-traveller / full-page-fixed-bg.html
Last active May 26, 2020 07:05
Full page background image (fixed)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Card</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
@light-traveller
light-traveller / maxWatch.sh
Created May 13, 2020 04:12
Increasing the amount of inotify watchers
# Debian, RedHat
# https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
@light-traveller
light-traveller / AnimatedGif.cs
Last active October 23, 2019 09:35
Prevent an Animated GIF from Looping Forever in WinForms
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
namespace Example
{
public partial class MyForm : Form
{
private Image _image;
@light-traveller
light-traveller / ModeStateExtensions.cs
Last active April 20, 2019 01:23
Get ASP.NET ModelState errors (all errors or by a specific field)
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using System;
using System.Collections.Generic;
using System.Linq;
public static class ModelStateExtensions
{
/// <summary>
/// Extracts error keys and error messages of all model fields
@light-traveller
light-traveller / ArrayMinMax.js
Last active August 16, 2018 12:08
[JavaScript Array Max/Min] element #js #javascript #array #array_min #array_max
/*
https://stackoverflow.com/a/31643591/1211622
*/
function arrayMax(array) {
return array.reduce((a, b) => Math.max(a, b));
}
function arrayMin(array) {
return array.reduce((a, b) => Math.min(a, b));