Skip to content

Instantly share code, notes, and snippets.

View amilos's full-sized avatar

Aleksandar Milosevic amilos

View GitHub Profile
@amilos
amilos / KebabCaseNamingStrategy.cs
Created October 9, 2017 16:56
Kebab case naming strategy extension for Newtonsoft.JSON library
using System.Text;
using Newtonsoft.Json.Serialization;
namespace Asseco.JsonUtils
{
// Adapted from SnakeCaseNamingStrategy from Newtonsoft.Json library
public class KebabCaseNamingStrategy : NamingStrategy
{
const char HYPHEN = '-';
const char UNDERSCORE = '_';
@amilos
amilos / KebabCaseResolver.cs
Last active October 9, 2017 16:50
Kebab case resolver extension for Newtonsoft.JSON library
using Newtonsoft.Json.Serialization;
namespace Asseco.JsonUtils
{
public class KebabCaseResolver : DefaultContractResolver
{
private Regex regex = new Regex("(?<!^)((?<=[a-zA-Z0-9])[A-Z][a-z])|((?<=[a-z])[A-Z])", RegexOptions.Compiled);
protected override string ResolvePropertyName(string propertyName)
{
@amilos
amilos / EventRecord.cs
Last active May 29, 2017 18:29
Example of model setup for JSON serialization with extension data
namespace Asseco.Rest.Models
{
[DataContract]
public partial class EventRecord
{
[JsonExtensionData]
internal Dictionary<string, object> udf;
public EventRecord(string EventKind = default(string))
{
@amilos
amilos / PeriodSerialization.cs
Created August 18, 2016 14:31
Using NodaTime Period class to serialize/deserialize ISO 8601 duration
using System;
using System.Text;
using System.IO;
using Newtonsoft.Json;
using NodaTime;
using NodaTime.Serialization.JsonNet;
namespace FormattingUtils
{
@amilos
amilos / gist:88cc4ba07868356495dc0608d2f6a552
Created August 17, 2016 06:25 — forked from tjrobinson/gist:0ad6c790e90d7a385eb1
ActiveDirectoryUserService.cs
using System;
using System.Collections.Generic;
using System.DirectoryServices.AccountManagement;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Thinktecture.IdentityServer.Core;
using Thinktecture.IdentityServer.Core.Models;
using Thinktecture.IdentityServer.Core.Services;
@amilos
amilos / dark-plus.css
Created July 18, 2016 17:59
Dark+ (Visual Studio) theme for JSONView Chrome extension
body {
background-color: rgba(30,30,30,1);
color: rgba(212,212,212,1);
font-size: 14px;
white-space: pre !important;
font-family: "Roboto Mono", "Source Code Pro", Menlo, "Ubuntu Mono", Monaco, Consolas, Courier, monospace;
padding: 30px 30px 20px;
}
.property {
@amilos
amilos / FriendlyId.cs
Last active March 10, 2016 19:22
Friendly ID generator that creates 10-character string identifiers
using System;
using System.Linq;
using System.Text;
namespace Asseco.MiscUtils
{
/*
* Based on Firebase ids but modified for shorter ids and base62 alphabet
*/