Skip to content

Instantly share code, notes, and snippets.

View JakeGinnivan's full-sized avatar
:shipit:

Jake Ginnivan JakeGinnivan

:shipit:
View GitHub Profile
@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()
{
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
{
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)
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);
}
//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>
@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"));
@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>()
{
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)
# Auto detect text files and perform LF normalization
* text=auto
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union
//Need http://nuget.org/packages/Microsoft.Bcl.Async
internal static class WebRequestExtensions
{
internal static Task<WebResponse> GetResponseAsync(this WebRequest request, TimeSpan timeout)
{
var asyncTask = Task.Factory.FromAsync<WebResponse>(request.BeginGetResponse, request.EndGetResponse, null);
var timeoutTask = TaskEx.Delay(timeout);
return TaskEx.WhenAny(asyncTask, timeoutTask)