Skip to content

Instantly share code, notes, and snippets.

View jonathascosta's full-sized avatar

Jonathas Costa jonathascosta

  • Porto, Portugal
View GitHub Profile
@jonathascosta
jonathascosta / TestDaoInstaller.cs
Created May 13, 2011 18:43
Instalador Windsor para objetos DAL
public class TestDaoInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
AllTypes.FromAssemblyNamed("YourProduct.DataAccess")
.BasedOn(typeof(IDao<,>))
.Configure(c => c.LifeStyle.Transient)
.WithService.Select((t, baseType) => t.GetInterfaces())
.BasedOn(typeof(IDao<>))
@jonathascosta
jonathascosta / LocalizedModelBinder.cs
Created May 17, 2011 20:27
Localized Model Binder for specified culture
public class LocalizedModelBinder : DefaultModelBinder
{
private readonly CultureInfo _cultureInfo;
public LocalizedModelBinder(string cultureName)
{
_cultureInfo = CultureInfo.GetCultureInfo(cultureName);
}
public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
using System.Linq;
using System.Text.RegularExpressions;
public static class StringExtensions
{
public static string ToUpper(this string name, string separator)
{
string upper = Regex
.Matches(name, "[A-Z][a-z]+")
.Cast<Match>()
@jonathascosta
jonathascosta / TypeExtensions.cs
Created May 20, 2011 19:53
Type extension methods
public static class TypeExtensions
{
public static bool IsNullableOrType<T>(this Type type)
where T : struct
{
return (type == typeof(T) || type == typeof(T?));
}
}
@jonathascosta
jonathascosta / gist:987644
Created May 23, 2011 21:20
String Extensions
public static class TypeExtensions
{
public static bool IsNullableOrType<T>(this Type type)
where T : struct
{
return (type == typeof(T) || type == typeof(T?));
}
}
public static class StringExtensions
@jonathascosta
jonathascosta / gist:987676
Created May 23, 2011 21:41 — forked from juanplopes/gist:987646
String Extensions
public static class TypeExtensions
{
public static Type GetValueTypeIfNullable(this Type type)
{
return type.IsNullable() ? type.GetGenericArguments()[0] : type;
}
public static bool IsNullable(this Type type)
{
return (type.IsGenericType && typeof(Nullable<>) == type.GetGenericTypeDefinition());
@jonathascosta
jonathascosta / ExtStoreResult.cs
Created September 15, 2011 16:44
ActionResult with Javascript for a Ext.Store
using System.Web.Mvc;
using Newtonsoft.Json;
namespace ActionResults
{
public class ExtStoreResult : ActionResult
{
public virtual string StoreName { get; set; }
public virtual object StoreData { get; set; }
@jonathascosta
jonathascosta / Competencia.cs
Created October 20, 2011 19:49
Classe Competência para lidar com mês/ano
public class Competencia
{
public Competencia(int mes, int ano)
{
try
{
new DateTime(ano, mes, 1);
}
catch (Exception)
{
@jonathascosta
jonathascosta / StateMachine.cs
Created October 28, 2011 11:40
Simple State Machine API
using System;
using System.Collections.Generic;
using System.Linq;
namespace Architecture.StateMachine
{
/// <summary>
/// Representa uma máquina de estados.
/// </summary>
/// <typeparam name="T">Tipo do estado.</typeparam>
@jonathascosta
jonathascosta / gist:1363986
Created November 14, 2011 13:52
Problem 30
public static long Solve()
{
var powers = new List<long>();
var numbers = new List<long>();
for (int i = 0; i < 10; i++)
powers.Add((long)BigInteger.Pow(i, 5));
for (int a = 0; a < 10; a++)
for (int b = 0; b < 10; b++)