Skip to content

Instantly share code, notes, and snippets.

View juanplopes's full-sized avatar
🌲
Is that a Segment Tree problem?

Juan Lopes juanplopes

🌲
Is that a Segment Tree problem?
View GitHub Profile
@juanplopes
juanplopes / gist:757685
Created December 28, 2010 20:41 — forked from tucaz/gist:757678
//C#
public T FindInList<T>(IEnumerable<T> source, IEnumerable<T> target)
{
return source.First(target.Contains)
//return source.Intersect(target).First();
}
//F#
//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))
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
public class MeuDependencyResolver : IDependencyResolver
{
private ILookup<Type, object> dependencias;
public MeuDependencyResolver()
{
this.dependencias = Dependencias().ToLookup(x => x.GetType());
}
private IEnumerable<object> Depencencias()
public class MeuDependencyResolver : IDependencyResolver
{
private ILookup<Type, object> lookup;
public MeuDependencyResolver()
{
var dependencias = new []
{
new DummyDependencia1(), new DummyDependencia2(), new DummyDependencia2_2()
};
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));
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;
@juanplopes
juanplopes / test.cs
Created April 18, 2011 16:19 — forked from ElemarJR/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()
@juanplopes
juanplopes / gist:987646
Created May 23, 2011 21:21 — forked from jonathascosta/gist:987644
String Extensions
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
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);