Skip to content

Instantly share code, notes, and snippets.

View gBritz's full-sized avatar
🎯
Focusing

Guilherme Britz Videira gBritz

🎯
Focusing
View GitHub Profile
@gBritz
gBritz / UnixTimestampConverter.cs
Created April 15, 2016 17:29
Unix timestamp converter with newtonsoft.json
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Infrastructure.Json
{
public class UnixTimestampConverter : DateTimeConverterBase
{
private static readonly DateTime _epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
@gBritz
gBritz / JsonContentTest.cs
Created March 31, 2016 13:37
Comparar json gerado com original do cliente
public class JsonContentTest
{
[Fact]
public void Testar_geracao_json()
{
var jsonContent = "{\"user_id\":0,\"app_user_id\":7,\"name\":null,\"first_name\":\"Teacher Britzola\",\"surname\":\"Four\",\"username\":\"952pyiwuc2\",\"password\":\"1y60cgKx\",\"email\":\"teacher.four@gedu.demo.smartlab.me\",\"birthdate\":\"1978-09-28T01:00:00\",\"gender\":\"male\",\"role\":\"teacher\",\"student\":null,\"teacher\":{\"school\":{\"id\":8,\"name\":\"Col\\u00e9gio Educar - DEMO\",\"federative_unit\":\"SP\",\"city\":\"S\\u00e3o Paulo\",\"zip\":\"03303904\"},\"classes\":[{\"id\":3,\"name\":\"A1\",\"stage\":null}]}}";
var obj = new
{
user_id = 0,
app_user_id = 7,
@gBritz
gBritz / FlurlTesting.cs
Created March 4, 2016 18:58
Testing Flurl with TestServer
public static async Task WriteAsync(this IOwinContext context, string content, IDictionary<string, string> headers = null)
{
foreach (var header in headers)
{
context.Response.Headers.Add(header.Key, new[] { header.Value });
}
await context.Response.WriteAsync(content);
}
@gBritz
gBritz / IpValidatorBenchmark.cs
Created March 4, 2016 16:14
Ip validator benchmark
using System;
using System.Net;
using System.Text.RegularExpressions;
using BenchmarkDotNet.Attributes;
[Config("jobs=job1,job2 " +
"columns=column1,column2 " +
"exporters=exporter1,exporter2 " +
"loggers=logger1,logger2 " +
"diagnosers=diagnoser1,diagnoser2 " +
@gBritz
gBritz / FreeGeoIP.cs
Created March 4, 2016 14:53
freegeoip with Flurl
public class FreeGeoIP
{
[JsonProperty("city")]
public string City { get; set; }
[JsonProperty("country_code")]
public string CountryCode { get; set; }
[JsonProperty("country_name")]
public string CountryName { get; set; }
@gBritz
gBritz / EnumTests.cs
Created November 24, 2015 19:15
Example test if all values of first enum type, constains in second enum type
[Theory]
[InlineData(typeof(BookType), typeof(BookType))]
public void GivenTwoEnums_WhenNamesOfFromNotContainsInToEnum_ShouldBeFalse(Type from, Type to)
{
var fromNames = Enum.GetNames(from);
var toNames = Enum.GetNames(to);
var namesThatNotContainsInToNamesQuery = fromNames.Where(name => !toNames.Contains(name));
var names = String.Join(", ", namesThatNotContainsInToNamesQuery.ToArray());
@gBritz
gBritz / DataAnnotationsExtensions.cs
Created November 5, 2015 18:15
Manual DataAnnotations Execution
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace Web.Common
{
public static class DataAnnotationsExtensions
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "1#", Justification = "customary")]
public static bool IsValidAnnotations<T>(this T instance, out ICollection<ValidationResult> results) where T : class
{
@gBritz
gBritz / MessageController.cs
Last active September 22, 2015 00:46
Resources .net in json
using System;
using System.Collections;
using System.Globalization;
using System.Linq;
using System.Web.Mvc;
using System.Web.UI;
namespace Web.Controllers
{
public class MessageController : Controller
@gBritz
gBritz / DataContext.cs
Created August 14, 2015 13:43
EF Migration by url - not recommend
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Migrations;
using System.Data.Entity.Migrations.Infrastructure;
using System.Data.Entity.Validation;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
@gBritz
gBritz / CssDuplicateSelectorWalker.cs
Last active August 29, 2015 14:25
Navegating syntactically parts of your css with CssSyntax
using CssSyntax;
using CssSyntax.SyntaxTree;
using System;
using System.Collections.Generic;
using System.Linq;
namespace CssDupfinder
{
public class CssDuplicateSelectorWalker : CssWalker
{