Skip to content

Instantly share code, notes, and snippets.

View lurumad's full-sized avatar
🏠
Working from home

Luis Ruiz Pavon lurumad

🏠
Working from home
View GitHub Profile
@lurumad
lurumad / DeleteExcludedFiles.ps1
Created February 16, 2018 08:21 — forked from mikesigs/DeleteExcludedFiles.ps1
PowerShell Script to Find (and delete) all excluded files in a Visual Studio Solution
<#
.SYNOPSIS
Find all files excluded from a Visual Studio solution with options to delete.
.DESCRIPTION
Finds all excluded files in all projects in the provided Visual Studio solution with options to delete the files.
.PARAMETER Solution
The path to the .sln file
@lurumad
lurumad / BearerTokensADFS
Created October 26, 2016 09:42
Using ADFS Tokens in WebApi 2
public class Startup
{
private static readonly string Realm = ConfigurationManager.AppSettings["ida:Wtrealm"];
private static readonly string AdfsMetadata = ConfigurationManager.AppSettings["ida:ADFSMetadata"];
public void Configuration(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
@lurumad
lurumad / WebApiUnitOfWork
Last active August 29, 2015 14:24
WebApi Unit of Work using DelegationHandler
public class UnitOfWorkDelegatingHandler : DelegatingHandler
{
protected override async Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
CancellationToken cancellationToken)
{
var response = await base.SendAsync(request, cancellationToken);
var isSafeMethod = request.Method == HttpMethod.Get || request.Method == HttpMethod.Head;
if (!response.IsSuccessStatusCode || isSafeMethod)
@lurumad
lurumad / JsonSplitter
Created December 11, 2014 08:31
Reto 7 MSDN
public class JsonSplitter
{
public static Result SplitShowsByGenre(string trendingShowsJson, string comedy)
{
var trendingShows =
JsonConvert.DeserializeObject<List<Movie>>(trendingShowsJson);
var comedyShows = trendingShows.Where(m => m.Genres.Contains(comedy));
var noComedyShows = trendingShows.Where(m => !m.Genres.Contains(comedy));
@lurumad
lurumad / Reto LINQ - Distinct
Created September 12, 2014 07:29
Reto LINQ - Distinct
//Obten una lista de clientes no repetidos sin usar el operador Distinct y en solo una línea
void Main()
{
var duplicatedCustomers = new List<Customer>
{
new Customer
{
Id = 1,
Name = "Luis"
@lurumad
lurumad / luruconemu
Created July 24, 2014 10:57
ConEmu Settings
<?xml version="1.0" encoding="utf-8"?>
<key name="Software">
<key name="ConEmu">
<key name=".Vanilla" modified="2014-07-24 12:56:50" build="140707">
<value name="ColorTable00" type="dword" data="00000000"/>
<value name="ColorTable01" type="dword" data="00800000"/>
<value name="ColorTable02" type="dword" data="00008000"/>
<value name="ColorTable03" type="dword" data="00808000"/>
<value name="ColorTable04" type="dword" data="00000080"/>
<value name="ColorTable05" type="dword" data="00800080"/>
@lurumad
lurumad / PaginatedList
Created July 18, 2014 07:24
Paginated List
using System;
using System.Collections.Generic;
using System.Linq;
using MongoDB.Driver;
namespace Luru.Collections
{
public class PaginatedList<T>
{
public int PageIndex { get; set; }
@lurumad
lurumad / TempDataDocument
Last active August 29, 2015 14:01
MongoCSharpDriver deserialize anonymous type
public class TempDataDocument
{
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
[BsonElement("key")]
public string Key { get; set; }
[BsonElement("value")]
[BsonSerializer(typeof(CustomSerializer))]
public object Value { get; set; }
}
@lurumad
lurumad / DictionaryExtensions
Last active August 29, 2015 14:01
Avoid repetitive use of ternary operation when we work with IDictionary<string, object>
public static T GetValue<T>(this IDictionary<string, object> dictionary, string key)
{
if (!dictionary.ContainsKey(key))
{
return default(T);
}
object data = dictionary[key];
return data != null && data.GetType() == typeof (T) ? (T) data : default(T);
@lurumad
lurumad / SslRequiredMessageHandler
Last active December 19, 2015 00:09
Requires SSL for WebAPI
public class SslRequiredMessageHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
CancellationToken cancellationToken)
{
if (!request.IsSecureConnection))
{
var response =
request.CreateErrorResponse(HttpStatusCode.Forbidden, "Https required");