Skip to content

Instantly share code, notes, and snippets.

View programmation's full-sized avatar

David Dancy programmation

View GitHub Profile
@programmation
programmation / task_dependency_manager
Created June 22, 2015 02:20
Task dependency manager from Stephen Toub MSDN article. Similar to NSOperationQueue / NSOperation on MacOS / iOS.
// https://msdn.microsoft.com/en-us/magazine/dd569760.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace OperationQueueTest
@programmation
programmation / threadsafe_imagesource
Created June 22, 2015 00:33
How to make sure only one ImageSource load is in flight at a time
// https://bugzilla.xamarin.com/show_bug.cgi?id=21981#c5
using Xamarin.Forms;
[assembly: ExportImageSourceHandler(typeof(UriImageSource), typeof(iOS.Renderers.ImageLoaderSourceHandler))]
namespace iOS.Renderers
{
using System.Collections.Generic;
using System.Threading;
@programmation
programmation / delayed_text_entry
Created June 21, 2015 23:20
How to delay response to user text entry until after user finishes typing
// http://forums.xamarin.com/discussion/comment/133731/#Comment_133731
public partial class Page1
{
public Page1()
{
this.InitializeComponent();
this.Entry.TextChanged += this.EntryOnTextChanged;
}
//
// https://msdn.microsoft.com/en-us/library/hh228604(v=vs.110).aspx
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
@programmation
programmation / async_factory.cs
Created May 4, 2015 07:04
Async factory method
// http://blog.stephencleary.com/2013/01/async-oop-2-constructors.html
public sealed class MyClass
{
private MyData asyncData;
private MyClass() { ... }
private async Task<MyClass> InitializeAsync()
{
asyncData = await GetDataAsync();
@programmation
programmation / async_noop.cs
Last active August 29, 2015 14:20
Async no-op
// http://blog.stephencleary.com/2015/04/a-tour-of-task-part-10-promise-tasks.html
interface IPlugin
{
// Permit each plugin to initialize asynchronously.
Task InitializeAsync();
}
class MyPlugin : IPlugin
{
@programmation
programmation / pcl_nugets.txt
Last active November 6, 2015 00:16
PCL NuGet packages
// List of interesting NuGet PCLs
Conditions
ExifLib
SharpSerializer
PCLStorage
BouncyCastlePCL (encryption)
Sockets
MathNet.Numerics
Zeroconf (Bonjour)
@programmation
programmation / gist:44edf45980b10276b14f
Created May 4, 2015 04:29
Xamarin Forms DataTemplateSelector
using System;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace Test
{
public class DataTemplateSelectorExtension : IMarkupExtension
{
public Page Page { get; set; }
@programmation
programmation / optional_interface.cs
Created May 4, 2015 04:26
Protocol pattern in C#
// http://www.knowing.net/index.php/2014/07/10/
interface IFoo
{
//Methods defined here, as always, must be implemented
void Necessary ();
}
static class IFoo_Extensions
{
@programmation
programmation / unmanaged_resource_holder.cs
Created May 4, 2015 04:23
Unmanaged resource holder template
// http://blog.adamkemp.com/2014/10/c-finalizers-and-idisposable.html
public class UnmanagedResourceHolder : IDisposable
{
private bool _disposed;
private OtherDisposableObject _otherDisposable;
public UnmanagedResourceHolder()
{
AcquireUnmanagedResource();