Skip to content

Instantly share code, notes, and snippets.

View CarlosLanderas's full-sized avatar

Carlos Landeras CarlosLanderas

View GitHub Profile
@CarlosLanderas
CarlosLanderas / condition_evaluator.ts
Last active September 21, 2016 06:09
Functional typescript
export function and<T>(conditions : Array<(T) => boolean>) : (obj:T) => boolean {
return (e: T) => conditions.every( c=> c(e));
}
@CarlosLanderas
CarlosLanderas / Boot.ts
Created September 21, 2016 06:13
Typescript metadata / decorators
import Main from "./main";
import {Program} from "./program";
Main.bootstrap(Program);
@CarlosLanderas
CarlosLanderas / AutofacRegister
Last active February 3, 2017 10:32
Delegate Autofac Register
builder.Register<SingleInstanceFactory>(ctx =>
{
var c = ctx.Resolve<IComponentContext>();
return t =>
{
object o;
return c.TryResolve(t, out o) ? o : null;
};
});
@CarlosLanderas
CarlosLanderas / CustomValueTask.cs
Last active July 4, 2017 20:18
Generalized Async Return Types in C# 7.0 sample code.
[AsyncMethodBuilder(typeof(AsyncCustomValueTaskMethodBuilder<>))]
[StructLayout(LayoutKind.Auto)]
public struct CustomValueTask<T>: IEquatable<CustomValueTask<T>>
{
internal readonly T _result;
internal readonly Task<T> _task;
public CustomValueTask(Task<T> task)
{
_task = task;
_result = default(T);
@CarlosLanderas
CarlosLanderas / aExerciseSolutions.MD
Last active February 4, 2024 07:49
A Tour of Go (https://tour.golang.org) - Exercise Solutions
@CarlosLanderas
CarlosLanderas / sourceAnalytics.js
Last active August 24, 2017 23:49
Source code analytics with sloc
const chalk = require('chalk');
const glob = require('glob');
const sloc = require('sloc');
const fs = require('fs');
let pattern = "**";
let jsExcludes = ['**/app.bundle.*', '**/node_modules/**', '**/lib/**'];
let slocKeys = ['total', 'comment', 'todo', 'source'];
let extension = process.argv.slice(2)[0];
let targetExtension = `*.${extension}`;
@CarlosLanderas
CarlosLanderas / Context.cs
Last active October 23, 2021 05:12
EF Core Model Builder extensions to apply global conventions
using Microsoft.EntityFrameworkCore;
namespace Microsoft.EntityFramework.Conventions.Extensions
{
public class Context : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.SetGlobalMaxLength(200);
modelBuilder.SetGlobalTablePrefix("tbl_");
@CarlosLanderas
CarlosLanderas / DatabaseReader.cs
Last active October 4, 2017 16:39
Dapper Query Map Collections
public IEnumerable<T1> ReadWithMap<T1, T2, TReturn>(Func<T1, object> key, Func<T1, string> targetMap) where TReturn : T1
{
var lookup = new Dictionary<object, T1>();
var targetType = typeof(T1);
var propertyFlags = BindingFlags.Public | BindingFlags.Instance;
gridReader.Read<T1, T2, T1>((t1, t2) =>
{
if (!lookup.TryGetValue(key(t1), out T1 t1Return))
{
@CarlosLanderas
CarlosLanderas / Server.cs
Last active November 15, 2020 20:43
Single Sign Asp.Net Core Server
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Server.HttpSys;
namespace Api
{
### Keybase proof
I hereby claim:
* I am carloslanderas on github.
* I am lande (https://keybase.io/lande) on keybase.
* I have a public key ASCj0FTIhQAEKSYMC1JhWLe9e49ZvmsL56xmvKissiQXaAo
To claim this, I am signing this object: