Skip to content

Instantly share code, notes, and snippets.

View InvaderZim85's full-sized avatar
🤖
Schroedinger's code: It's only a bug if someone notices it!

Andreas InvaderZim85

🤖
Schroedinger's code: It's only a bug if someone notices it!
  • EMP
  • Germany
  • 07:12 (UTC +02:00)
View GitHub Profile
@InvaderZim85
InvaderZim85 / Tsql_SmallDateTimeVSDateTime.txt
Created April 9, 2021 11:04
TSQL - SMALLDATETIME vs. DATETIME
+---------------------+---------------------+---------------------+
| Test-Wert | SMALLDATETIME | DATETIME |
+---------------------+---------------------+---------------------+
| 09.04.2021 23:59:00 | 09/04/2021 23:59:00 | 09/04/2021 23:59:00 |
| 09.04.2021 23:59:01 | 09/04/2021 23:59:00 | 09/04/2021 23:59:01 |
| 09.04.2021 23:59:02 | 09/04/2021 23:59:00 | 09/04/2021 23:59:02 |
| 09.04.2021 23:59:03 | 09/04/2021 23:59:00 | 09/04/2021 23:59:03 |
| 09.04.2021 23:59:04 | 09/04/2021 23:59:00 | 09/04/2021 23:59:04 |
| 09.04.2021 23:59:05 | 09/04/2021 23:59:00 | 09/04/2021 23:59:05 |
| 09.04.2021 23:59:06 | 09/04/2021 23:59:00 | 09/04/2021 23:59:06 |
@InvaderZim85
InvaderZim85 / CheckObjectIsList.cs
Created February 5, 2021 15:54
Check if an object is a list
// Method to check if the given object is a list
bool IsList(object value)
{
return value is IList && value.GetType().IsGenericType && value.GetType().GetGenericTypeDefinition().IsAssignableFrom(typeof(List<>)));
}
// Some object
object value = new List<int> { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
if (IsList(value))
/// <summary>
/// Provides the main class for the view models
/// </summary>
internal class ViewModelBase : ObservableObject
{
/// <summary>
/// The instance of the mah apps dialog coordinator
/// </summary>
private readonly IDialogCoordinator _dialogCoordinator;
@InvaderZim85
InvaderZim85 / SecureStringExtension.cs
Created March 20, 2020 15:08
Extension to convert a string into a SecureString and the other way
// Works with .NET Framework, .NET Core and .NET Standard
using System;
using System.Runtime.InteropServices;
using System.Security;
/// <summary>
/// Provides several function to interact with a <see cref="SecureString"/>
/// </summary>
public static class SecureStringExtension
{
@InvaderZim85
InvaderZim85 / NancyCustomAttributeMetadataClass.cs
Created November 22, 2019 21:50
Usage of the metadata base class
public class InfoMetadataModule : MetadataBase<InfoModule> { }
public class MetadataBase<TModule> : MetadataModule<CustomMetadata> where TModule : class
{
protected MetadataBase()
{
AddDescription();
}
private void AddDescription()
{
var metaData = GetCustomMetadata<TModule, RouteDescriptionAttribute>();
@InvaderZim85
InvaderZim85 / NancyCustomAttributeUsageMetadata.cs
Last active November 22, 2019 21:42
Usage of the custom attribute in the meta module
public class InfoMetadataModule : MetadataModule<CustomMetadata>
{
public InfoMetadataModule()
{
var metaData = GetCustomMetadata();
foreach (var entry in metaData)
{
Describe[entry.Name] = x => new CustomMetadata(x, entry.Description);
}
@InvaderZim85
InvaderZim85 / NancyCustomAttributeUsage.cs
Last active November 22, 2019 19:35
Usage of the custom attribute
public sealed class InfoModule : NancyModule
{
[RouteDescription("HelloRoute", "Returns a simple hello message.")]
[RouteDescription("InfoRoute", "Returns the current date time and a short hello message.")]
public InfoModule()
{
Get("/", _ => Response.AsText("Hello from Nancy!", name: "HelloRoute");
Get("/info", _ =>
{
@InvaderZim85
InvaderZim85 / NancyCustomAttribute.cs
Last active November 22, 2019 19:28
Custom attribute for the NancyFx metadata
[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = true)]
public class RouteDescriptionAttribute : Attribute
{
public string Name { get; }
public string Description { get; }
public RouteDescriptionAttribute(string name, string description)
{
Name = name;
Description = description;
@InvaderZim85
InvaderZim85 / GapList.cs
Created September 13, 2019 10:13
Returns the gap in list of type int
public static List<int> GetGaps(List<int> originalList)
{
// Check if the list is empty
if (originalList == null)
return new List<int>();
// Order the list
originalList = originalList.OrderBy(o => o).ToList();
// Get the first element