Skip to content

Instantly share code, notes, and snippets.

Avatar
This is not a verified profile. Or is it?

Juan Lopes juanplopes

This is not a verified profile. Or is it?
View GitHub Profile
View gist:1024285
public static IEnumerable<IList<T>> BatchAggregate<T>(this IEnumerable<T> source, int batchSize)
{
for (int page = 0; page < source.Count(); page = page + batchSize)
{
var list = source
.Skip(page)
.Take(batchSize)
.ToList();
yield return list;
View scan.cs
public IEnumerable<Token> Scan(IEnumerable<char> source)
{
var currentState = StatesTable.InitialStage;
var currentValue = "";
Func<Token> markPartialStop = () =>
{
if (currentState.IsStop)
{
var result = new Token(currentState.ResultingTokenId, currentValue);
@juanplopes
juanplopes / gist:987646
Created May 23, 2011 — forked from jonathascosta/gist:987644
String Extensions
View gist:987646
public static class TypeExtensions
{
public static Type GetValueTypeIfNullable(this Type type)
{
return (type.IsGenericType && typeof(Nullable<>) == type.GetGenericTypeDefinition())
? type.GetGenericArguments()[0] : type;
}
}
public static class StringExtensions
View test.cs
[Test]
public static void Class_AllStaticMethodsShouldBeDecoratedWithDebuggerStepThroughAttribute()
{
var methods = StaticMethodsWithout(typeof(Mooble.Util.StringExtensions), typeof(DebuggerStepThroughAttribute))
methods.Count.Should.Be(0);
}
IEnumerable<MethodInfo> StaticMethodsWithout(Type type, Type attribute)
{
return from m in type.GetMethods()
View 1 - StronglyTypedEnum.cs
public struct MyEnum
{
public static readonly MyEnum Value1 = new MyEnum("value1");
public static readonly MyEnum Value2 = new MyEnum("value2");
readonly string name;
MyEnum(string name) : this()
{
this.name = name;
View Get Specific Generic Interface.cs
var intForm = Type.GetType("ModuloControle.IMessageForm'1").MakeGenericType(myDesiredType)
GetType().Assembly.GetTypes()
.Where(x=>!x.IsAbstract && typeof(Form).IsAssignableFrom(x) && intForm.IsAssignableFrom(x))
.Select(x => (Form)Activator.CreateInstance(x));
View MeuDependencyResolver.cs
public class MeuDependencyResolver : IDependencyResolver
{
private ILookup<Type, object> dependencias;
public MeuDependencyResolver()
{
this.dependencias = Dependencias().ToLookup(x => x.GetType());
}
private IEnumerable<object> Depencencias()
View MeuDependencyResolver.cs
public class MeuDependencyResolver : IDependencyResolver
{
private ILookup<Type, object> lookup;
public MeuDependencyResolver()
{
var dependencias = new []
{
new DummyDependencia1(), new DummyDependencia2(), new DummyDependencia2_2()
};
View DB vs FS
Felipe:
quer minha opinião?
Rodrigo Vidal:
sim :D
Felipe:
na grande maioria dos casos, tanto faz
não terá diferença
em casos que um FileSystem é um problema, o DB será um problema também
e vice-cersa
vice-versa
View gist:759026
//C#
public T FindInList<T>(IEnumerable<T> source, IEnumerable<T> target)
{
return source.First(target.Contains)
}
//F#
let FindInList (source : seq<_>) (target : seq<_>) = source.First(Func<_,bool>(target.Contains))