Skip to content

Instantly share code, notes, and snippets.

View asimmon's full-sized avatar

Anthony Simmon asimmon

View GitHub Profile
@asimmon
asimmon / cache-result-aop-src-cache-provider.cs
Created November 20, 2015 15:49
Caching method results with AOP - Cache Provider
public interface ICacheProvider
{
object Get(string key);
void Put(string key, object value, int duration);
bool Contains(string key);
}
public class MemoryCacheProvider : ICacheProvider
@asimmon
asimmon / cache-result-aop-src-cache-attr.cs
Created November 20, 2015 15:50
Caching method results with AOP - CacheResultAttribute
public class CacheResultAttribute : Attribute
{
public int Duration { get; set; }
}
@asimmon
asimmon / cache-result-aop-src-cache-interceptor.cs
Created November 20, 2015 15:51
Caching method results with AOP - CacheResultInterceptor
public class CacheResultInterceptor : IInterceptor
{
private readonly ICacheProvider _cache;
public CacheResultInterceptor(ICacheProvider cache)
{
_cache = cache;
}
public CacheResultAttribute GetCacheResultAttribute(IInvocation invocation)
@asimmon
asimmon / cache-result-aop-src-autofac-cfg.cs
Created November 20, 2015 15:52
Caching method results with AOP - Autofac Configuration
public class MyModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<MemoryCacheProvider>()
.As<ICacheProvider>()
.SingleInstance();
builder.RegisterType<CacheResultInterceptor>()
.SingleInstance();
@asimmon
asimmon / eventtocommand-xamarin-forms-example-wm.cs
Created November 20, 2015 15:55
EventToCommand Xamarin Forms - Example ViewModel
public class HomeViewModel : ViewModelBase
{
public ObservableCollection<PersonViewModel> People { get; set; }
public RelayCommand<PersonViewModel> SayHelloCommand { get; set; }
public HomeViewModel()
{
People = new ObservableCollection<PersonViewModel>
{
@asimmon
asimmon / eventtocommand-xamarin-forms-example-ea-converter.cs
Created November 20, 2015 15:56
EventToCommand Xamarin Forms - Exempe EventArgs Converter
public class ItemTappedEventArgsConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var eventArgs = value as ItemTappedEventArgs;
if (eventArgs == null)
throw new ArgumentException("Expected TappedEventArgs as value", "value");
return eventArgs.Item;
}
@asimmon
asimmon / eventtocommand-xamarin-forms-example-view.xaml
Last active November 20, 2015 15:57
EventToCommand Xamarin Forms - Example View
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:b="clr-namespace:HelloEventToCommand.Behaviors;assembly=HelloEventToCommand" xmlns:c="clr-namespace:HelloEventToCommand.Converters;assembly=HelloEventToCommand" x:Class="HelloEventToCommand.Views.HomeView">
<ContentPage.Resources>
<ResourceDictionary>
<c:ItemTappedEventArgsConverter x:Key="ItemTappedConverter" />
</ResourceDictionary>
</ContentPage.Resources>
<ListView ItemsSource="{Binding People}">
<ListView.Behaviors>
@asimmon
asimmon / eventtocommand-xamarin-forms-src-behavior.cs
Last active January 17, 2016 17:21
EventToCommand Xamarin Forms - Behavior Source
public class EventToCommandBehavior : BindableBehavior<View>
{
public static readonly BindableProperty EventNameProperty = BindableProperty.Create<EventToCommandBehavior, string>(p => p.EventName, null);
public static readonly BindableProperty CommandProperty = BindableProperty.Create<EventToCommandBehavior, ICommand>(p => p.Command, null);
public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create<EventToCommandBehavior, object>(p => p.CommandParameter, null);
public static readonly BindableProperty EventArgsConverterProperty = BindableProperty.Create<EventToCommandBehavior, IValueConverter>(p => p.EventArgsConverter, null);
public static readonly BindableProperty EventArgsConverterParameterProperty = BindableProperty.Create<EventToCommandBehavior, object>(p => p.EventArgsConverterParameter, null);
private Delegate _handler;
private EventInfo _eventInfo;
@asimmon
asimmon / eventtocommand-xamarin-forms-src-2.cs
Created November 20, 2015 15:59
EventToCommand Xamarin Forms - BindableBehavior Source
public class BindableBehavior<T> : Behavior<T> where T : BindableObject
{
public T AssociatedObject { get; private set; }
protected override void OnAttachedTo(T visualElement)
{
base.OnAttachedTo(visualElement);
AssociatedObject = visualElement;
@asimmon
asimmon / nginx-rproxy-kestrel.conf
Created February 9, 2016 01:54
Nginx configuration for reverse proxying Kestrel
server {
# Port and domain
listen 80;
server_name aspnet.local;
# Path to the wwwroot folder
root /home/developer/projects/WebApplicationBasic/wwwroot;
# Static content
location ~ \.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm|woff2|svg)$ {