Skip to content

Instantly share code, notes, and snippets.

View JakeGinnivan's full-sized avatar
:shipit:

Jake Ginnivan JakeGinnivan

:shipit:
View GitHub Profile
var predicate = PredicateBuilder.True<Person>();
if (filderOptions.FirstName != null)
predicate = predicate.AndAlso(p=>p.FirstName == "Alex");
if (filderOptions.SomeNullable.HasValue)
predicate = predicate.AndAlso(p=>p.SomeProp == filterOptions.SomeNullable.Value);
var where = queryable.Where(predicate);
// will create an expresion which looks like this: p => true && p.FirstName == "Alex" && p.SomeProp == filterOptions.SomeNullable.Value)
@JakeGinnivan
JakeGinnivan / gist:3824725
Created October 3, 2012 03:09
PredicateBuilder
public static class PredicateBuilder
{
public static Expression<Func<T, bool>> True<T>()
{
return Expression.Lambda<Func<T, bool>>(Expression.Constant(true), Expression.Parameter(typeof(T)));
}
public static Expression<Func<T, bool>> False<T>()
{
@JakeGinnivan
JakeGinnivan / gist:3671586
Created September 8, 2012 03:28
Jsonp Media formatter
/// <summary>
/// Handles JsonP requests when requests are fired with text/javascript
/// </summary>
public class JsonpFormatter : JsonMediaTypeFormatter
{
public JsonpFormatter()
{
SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/javascript"));
//In generic.xaml
<Style TargetType="{x:Type Scaffolding:SearchScaffold}">
<Setter Property="BorderThickness"
Value="0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Scaffolding:SearchScaffold}">
<Controls:MetroContentControl>
public static class Retry
{
public const int WindowWaitDefault = 30;
public const int ElementWaitDefault = 10;
private const int RetryIntervalInMs = 200;
public static Window ForDefault(Func<Window> getMethod)
{
return For(getMethod, WindowWaitDefault);
}
var save = new ButtonExtras(ButtonType.Custom, "Save", "Saves this modified post to your blog");
var saveAs = new ButtonExtras(ButtonType.Custom, "Save As", "Saves this blog post as a local markdown file");
var publish = new ButtonExtras(ButtonType.Custom, "Publish As", "Publishes this post to another blog, or as another post");
dialogService.ShowConfirmationWithCancel("Markpad", "What do you want to do?", "", save, saveAs, publish);
if (save.WasClicked)
return base.Publish();
if (saveAs.WasClicked)
return SaveAs();
if (publish.WasClicked)
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using CCWin.Core.Extensions;
namespace CCWin.App.Infrastructure.Behaviours
{
@JakeGinnivan
JakeGinnivan / gist:3282830
Created August 7, 2012 07:30
Testing async commands
//Your code you are testing:
public IAsyncCommand SignInCommand { get; private set; }
public ctor()
{
SignInCommand = new AwaitableDelegateCommand(Login);
}
private async Task Login()
{
<entry>
<record>701</record>
<time>2012/07/15 09:02:40.463</time>
<type>Error</type>
<source>Editor or Editor Extension</source>
<description>System.InvalidOperationException: Could not find the component IColorThemeManager in the chain of component containers.&#x000D;&#x000A; at JetBrains.Application.Components.ComponentContainerEx.GetComponent[TInterface](IComponentContainer container)&#x000D;&#x000A; at JetBrains.VsIntegration.DevTen.Markup.VsQuickInfoSource.AugmentQuickInfoSession(IQuickInfoSession session, IList`1 quickInfoContent, ITrackingSpan&amp; applicableToSpan)&#x000D;&#x000A; at Microsoft.VisualStudio.Language.Intellisense.Implementation.QuickInfoSession.Recalculate()&#x000D;&#x000A; at Microsoft.VisualStudio.Language.Intellisense.Implementation.QuickInfoSession.Start()&#x000D;&#x000A; at Microsoft.VisualStudio.Language.Intellisense.Implementation.DefaultQuickInfoController.OnTextView_MouseHover(Object sender, MouseHoverEventArgs e)&#x000D;&#x000A; at Microsoft.V
public HttpResponseMessage Something()
{
if (someErrorCondition)
{
return new HttpResponseMessage<ErrorResponse>(new ErrorResponse("Blah error occured"), HttpStatusCode.500); // Whatever the code is
}
return new HttpResponseMessage<Result>(myResult);
}