Skip to content

Instantly share code, notes, and snippets.

rdavisau / CocosExtensions.cs
Last active Aug 29, 2015
CocosSharp Extension Methods - Helpers for actions, layout, sizing, drawing
View CocosExtensions.cs
Snippet Name: CocosSharp Extension Methods
Platform: All
Function: CocosSharp helpers for actions, layout, sizing, drawing
- Awaitable CCNode.RunActionsWithTask - allows you to await the running of a set of actions (for example, in order to not proceed with subsequent code till an animation completes), without having to explicitly calculate the duration of the actions or use a callback.
- Easy relative positioning with CCNode.PlaceAt - allows you to position a CCNode relative to the boundaries of a parent CCNode. Fluent style, so can be used at initialisation time.
- Easy filled colours with CCDrawNode.FillWith and quick sprite initialisation with CCNode.WithSprite, also fluent.
- Quick insetting or outsetting with CCSize.MultiplyBy.
rdavisau / InlineTableViewSource
Last active Aug 29, 2015
View InlineTableViewSource
Snippet Name: InlineTableViewSource
Platform: iOS
Function: A subclass of UITableViewSource that allows you to define UITableViewDataSource and UITableViewDelegate methods inline, rather than subclassing. Lets you take advantage of closures and use tableviews where you can't create subclasses, like in Xamarin Sketches (compile and reference).
Funcs/Actions are prefixed with "_", feel free to alter if this disagrees with your styling guidelines.
var cellId = new NSString("cell");
rdavisau / TaskTimeout.cs
Created Apr 17, 2015
Timeout extension method for Task<T>
View TaskTimeout.cs
// I don't remember where this is taken/adapted from.
public static class AsyncExtensions
public static async Task<T> TimeoutAfter<T>(this Task<T> task, TimeSpan timeout, CancellationTokenSource cancellationTokenSource = null)
if (task == await Task.WhenAny(task, Task.Delay(timeout)))
return await task;
if (cancellationTokenSource != null)
rdavisau / BetterTcpSocketClient
Last active Aug 29, 2015
ITcpSocketClient implementation with disconnected detection
View BetterTcpSocketClient
public class BetterTcpSocketClient : ITcpSocketClient
private TcpSocketClient _backingTcpSocketClient = new TcpSocketClient();
private readonly Stream _readBuffer = new BlockingMemoryStream();
private CancellationTokenSource _canceller;
public EventHandler<TcpSocketConnectedEventArgs> Connected { get; set; }
public EventHandler<TcpSocketDisconnectedEventArgs> Disconnected { get; set; }
public EventHandler<ErrorEventArgs> Errored { get; set; }
public Stream ReadStream
rdavisau / BetterUdpSocket
Created Apr 20, 2015
Wrapper for sockets-for-pcl UdpSocketReceiver that provides a blocking `Receive` call
View BetterUdpSocket
public class BetterUdpSocket : IDisposable
private BlockingCollection<byte[]> _readBuffer;
private readonly UdpSocketReceiver _backingUdpSocketReceiver = new UdpSocketReceiver();
public BetterUdpSocket()
_backingUdpSocketReceiver.MessageReceived += OnMessageReceived;
rdavisau / SocketHelpersDemo.linq
Last active Aug 29, 2015
LINQPad script demonstrating how to use service discovery and the JsonProtocolMessenger
View SocketHelpersDemo.linq
<Query Kind="Program">
<NuGetReference Prerelease="true">rda.SocketHelpers</NuGetReference>
rdavisau / DU.fsx
Created Aug 10, 2015
Akka.Cluster + Discriminated Union test
View DU.fsx
open System
open System.IO
open System.Net
open Akka
open Akka.Actor
open Akka.FSharp
open Akka.Remote
open Akka.Actor
open Akka.Cluster
rdavisau / AcceptSelfSignedCertificateWebView.cs
Created Dec 3, 2015
A UIWebView subclass for Xamarin iOS that accepts self-signed certificates. Note the caveats at
View AcceptSelfSignedCertificateWebView.cs
public class AcceptSelfSignedCertificateWebView : UIWebView
private NSUrlRequest _failedRequest;
private bool _authenticated;
private bool OnShouldStartLoad(UIWebView webView, NSUrlRequest request, UIWebViewNavigationType navigationType)
var result = _authenticated;
if (!_authenticated)
rdavisau / GetXamarinApps.cs
Created Nov 5, 2015
Checks your iTunes folder for any .ipas that look like Xamarin apps
View GetXamarinApps.cs
void Main()
var myXamarinApps =
.EnumerateFiles(Path.Combine(Environment.GetEnvironmentVariable("HOMEPATH"), @"Music\iTunes\iTunes Media\Mobile Applications"), "*.ipa")
.Where(f=> ZipFile.Open(f, ZipArchiveMode.Read)
.Any(e=> e.FullName.Contains(".monotouch-")));
foreach (var app in myXamarinApps)
rdavisau / 💣.cs
Created Oct 24, 2016
HockeyApp UnobservedTaskException
View 💣.cs
using System;
using System.Threading.Tasks;
using Foundation;
using HockeyApp.iOS;
using UIKit;
namespace HockeyCrash
public class AppDelegate : UIApplicationDelegate