Skip to content

Instantly share code, notes, and snippets.

Juan María Hernández jmhdez

Block or report user

Report or block jmhdez

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Builders.cs
public static class Build
{
public static OrderBuilder Order(Cutomer customer)
{
return new OrderBuilder(customer);
}
public static CustomerBuilder Customer(string name)
{
return new CustomerBuilder(name);
@jmhdez
jmhdez / gist:6669478
Last active Dec 23, 2015
Enumerators y Dispose
View gist:6669478
Una consulta básica usando Linq-to-NHibernate (con EF supongo que sería parecido)
var dbQuery = session.Query<Product>();
El IEnumerable que devuelve, internamente tiene un Enumerator parecido a esto:
IEnumerator<Product> GetEnumerator() {
using (var reader = command.ExecuteReader())
{
while (reader.Read())
@jmhdez
jmhdez / console.js
Last active Dec 14, 2016
Javascript console replacement
View console.js
(function(window, document) {
// Create the DOM structure to hold the console messages
var div = document.createElement("div");
div.style.cssText = "position: absolute; " +
"top: 5px; left: 5px; right: 5px; bottom: 5px; " +
"padding: 10px; " +
"overflow-y: auto; " +
"display: none; " +
@jmhdez
jmhdez / AsDict.cs
Last active Dec 22, 2015
Extension Method para convertir un objeto anónimo en un IDictinary
View AsDict.cs
public static class Extensions
{
public IDictionary<string, object> AsDict(this object obj)
{
return obj.GetType().GetProperties().ToDictionary(x => x.Name, x => x.GetValue(obj, null))
}
}
var obj = new { Name = "Lucas", Age = 14 }.AsDict();
@jmhdez
jmhdez / Elements.cs
Last active Dec 20, 2015
Compartiendo elementos en posiciones dependientes del contenedor
View Elements.cs
public interface IElement
{
IEnumerable<ChildElement> Children { get; }
}
public class ChildElement
{
public readonly IElement Value;
public readonly Point Point;
@jmhdez
jmhdez / Sample.cs
Last active Dec 19, 2015
Unas cuantas opciones para refactorizar un método a la hora de testearlo
View Sample.cs
// Situación inicial
public class OrderStatsCalculator
{
// Inyectado por constructor. En todos los casos lo hago igual.
private IOrderRepository repository;
// Esto se puede testear con un mock/stub/fake/etc. que inyectes por
// el constructor
public int Calculate()
{
@jmhdez
jmhdez / Id.cs
Created Apr 14, 2013
Id implementation using phantom types
View Id.cs
public struct Id<T>
{
public readonly int Value;
public Id(int value)
{
this.value = value;
}
public static implicit operator Id<T>(int value)
@jmhdez
jmhdez / DuckType.cs
Created Dec 16, 2012
Duck typing con C# preparado para realizar implementaciones de interfaces con objetos anónimos
View DuckType.cs
// Required libs
// - NUnit
// - Castle.DynamicProxy
using System;
using System.Linq;
using System.Reflection;
using Castle.DynamicProxy;
using NUnit.Framework;
@jmhdez
jmhdez / DuckType.cs
Created Dec 8, 2012
Duck Typing con C#
View DuckType.cs
// Required libs
// - NUnit
// - Castle.DynamicProxy
using System;
using System.Linq;
using System.Reflection;
using Castle.DynamicProxy;
using NUnit.Framework;
@jmhdez
jmhdez / GoToPlugin.java
Created Jun 22, 2012
Sample Cordova Plugin for Android
View GoToPlugin.java
package koalite.cordova;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.apache.cordova.api.PluginResult.Status;
import org.json.JSONArray;
import android.content.Intent;
import android.net.Uri;
public class GoToPlugin extends Plugin {
You can’t perform that action at this time.