Skip to content

Instantly share code, notes, and snippets.

@LSTANCZYK
LSTANCZYK / BooleanJsonConverter.cs
Created February 12, 2018 21:08 — forked from randyburden/BooleanJsonConverter.cs
A Json.NET JsonConverter that can handle converting the following values into boolean values: true, false, yes, no, y, n, 1, 0.
using System;
using Newtonsoft.Json;
namespace JsonConverters
{
/// <summary>
/// Handles converting JSON string values into a C# boolean data type.
/// </summary>
public class BooleanJsonConverter : JsonConverter
{
@LSTANCZYK
LSTANCZYK / gist:a880e1f46672fa909b40554e3abacb02
Created December 9, 2017 00:54 — forked from darrelmiller/gist:28221417620db2973a25
Coloured Request/Response console logger
public class ConsoleRequestLogger : DelegatingHandler
{
protected async override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("> {0} {1}",request.Method,request.RequestUri.GetComponents(UriComponents.PathAndQuery, UriFormat.SafeUnescaped));
ProcessHeader(request.Headers, (name, value) => Console.WriteLine("> {0}: {1}", name, value));
if (request.Content != null)
{
@LSTANCZYK
LSTANCZYK / gist:70a176b3f8cc6bb9a0c1a0876452bb50
Created December 9, 2017 00:53 — forked from darrelmiller/gist:8548166
How to tell Web API 2.1 to allow errors to propagate up the MessageHandler pipeline so all exceptions can be converted to HttpResponseMessages in one place.
class Program
{
static void Main(string[] args)
{
var server = WebApp.Start("http://localhost:1002/", (app) =>
{
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
config.Services.Replace(typeof(IExceptionHandler), new RethrowExceptionHandler());
@LSTANCZYK
LSTANCZYK / PrettyXml.cs
Created November 27, 2017 20:22 — forked from kristopherjohnson/PrettyXml.cs
Example of pretty-printing XML in C# using the XmlWriter class
using System;
using System.Text;
using System.Xml;
using System.Xml.Linq;
static string PrettyXml(string xml)
{
var stringBuilder = new StringBuilder();
var element = XElement.Parse(xml);
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.Serialization.Json;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.Text;
using System.Threading;

yUML Test On GitHub

yUML is a simple tool for embedding UML diagrams in wikis and blogs without needing any UML or diagramming tools.

Here's an idea of how it could be used in your repository readme.markdown or wiki.

View the RAW source to see how images are made.

Example

[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class RequiredIfEmptyAttribute : ValidationAttribute, IClientValidatable
{
private readonly string[] _dependentProperties;
public RequiredIfEmptyAttribute(params string[] dependentPropertieses)
{
_dependentProperties = dependentPropertieses;
}
@LSTANCZYK
LSTANCZYK / AllowedValuesAttribute.cs
Created September 25, 2017 01:55 — forked from Grinderofl/AllowedValuesAttribute.cs
String property allowed values with dropdown box and MVC model validation
// Usage:
// [AttributeUsage("Option1", "Option2", "Option3")]
// public string MyTestAttribute { get; set; }
//
// In view:
// @Html.DropDownListFor(x => x.MyTestAttribute)
//
// Result:
// Dropdown list with 3 options.
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class DateComparerAttribute : ValidationAttribute, IClientValidatable
{
/// <summary>
/// If set will use DateTime.AddDays to specify the Min Valid Date
/// </summary>
public double MinDateAddDaysFromNow
{
get { return _minDateAddDaysFromNow; }
set
@LSTANCZYK
LSTANCZYK / CreditCardAttribute.cs
Created September 25, 2017 01:55 — forked from bjcull/CreditCardAttribute.cs
Credit Card Validator Attribute for ASP.NET MVC 3
/// ASP.NET MVC 3 Credit Card Validator Attribute
/// by Ben Cull - 4 November 2010
///
/// With special thanks to:
/// Thomas @ Orb of Knowledge - http://orb-of-knowledge.blogspot.com/2009/08/extremely-fast-luhn-function-for-c.html
/// For the Extremely fast Luhn algorithm implementation
///
/// And Paul Ingles - http://www.codeproject.com/KB/validation/creditcardvalidator.aspx
/// For a timeless blog post on credit card validation