Skip to content

Instantly share code, notes, and snippets.

View D34NM's full-sized avatar
🎯
Focusing

D34N D34NM

🎯
Focusing
View GitHub Profile
class IpV6
{
private readonly string _originalValue;
public IpV6(string aValue)
{
_originalValue = aValue;
}
public string Compress()
@D34NM
D34NM / RoundingToNearestMinuteUtc.cs
Last active July 22, 2020 11:13
Rounding the DateTime to the nearest minute
internal static DateTime RoundToNearestMinuteUtc(this DateTimeOffset dt)
{
var diff = 0;
var minute = TimeSpan.FromMinutes(1);
var result = (double)(dt.Ticks % minute.Ticks) / minute.Ticks;
if (result >= 0.5)
{
diff = 1;
}
@D34NM
D34NM / HttpVerb.cs
Last active March 12, 2020 20:11
The HTTP Verbs and documentation.
namespace Example
{
/// <summary>
/// HTTP defines a set of request methods to indicate the desired action to be performed for a given resource.
/// Although they can also be nouns, these request methods are sometimes referred to as HTTP verbs.
/// Each of them implements a different semantic, but some common features are shared by a group of them: e.g. a request method can be safe, idempotent, or cacheable.
///
/// <see cref="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods"/>
/// </summary>
public static class HttpVerb
@D34NM
D34NM / Example.cs
Last active July 30, 2018 08:39
Overriding Equals, GetHashCode and implementing IEquatable<T>
public sealed class Example : IEquatable<Example>
{
public Example(string content)
{
Content = content;
}
public string Content { get; }
public bool Equals(Example other)
@D34NM
D34NM / DynamicMethod.cs
Created July 2, 2018 17:26
Runtime reflection and instantiation of the object using DynamicMethod.
public delegate object ConstructorDelegate();
public ConstructorDelegate GetConstructor(string typeName)
{
var type = Type.GetType(typeName);
var ctor = type.GetConstructor(new Type[0]);
var methodName = type.Name + "Ctor";
var dynamicMethod = new DynamicMethod(methodName, type, new Type[0], typeof(Activator));
var ilgen = dm.GetILGenerator();
@D34NM
D34NM / Program.cs
Created July 1, 2018 19:37
Implementing IEquatable<T>
internal enum Foo
{
Bar = 0
}
internal struct MyStuct : IEquatable<MyStuct>
{
private static readonly EqualityComparer<Foo> Eq = EqualityComparer<Foo>.Default;
public MyStuct(Foo foo)
@D34NM
D34NM / node.cmd
Created December 25, 2017 15:33
Some useful npm commands
npm list -g --depth=0 :: Show list of the globally installed packages with their version
@D34NM
D34NM / InsertSort.cs
Created March 27, 2017 20:00
Implementation of the Insert sort algorithm.
public int[] InsertSort(int[] array)
{
for (int i = 1; i < array.Length; i++)
{
int j = i;
while ((j > 0) && (array[j] < array[j - 1]))
{
int tmp = array[j - 1];
array[j - 1] = array[j];
array[j] = tmp;
@D34NM
D34NM / Product.cs
Created March 27, 2017 17:07
ICloneable example. Clean way to do a deep copy of the objects.
using System;
namespace DotNetPlayground
{
public class Product : ICloneable
{
public string Name { get; set; }
public float Price { get; set; }
@D34NM
D34NM / Stack.cs
Created March 23, 2017 19:03
Basic implementation of Stack.
using System;
namespace DataStructures
{
public class Stack<T>
{
#region Fields
private int _count;
private T[] _values;