Skip to content

Instantly share code, notes, and snippets.

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 / 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 / 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 / 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 / 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.