Skip to content

Instantly share code, notes, and snippets.

@kentcb
kentcb / gist:aafc739ec1958af75289
Created March 13, 2015 03:19
iOS bug wrt UITableViewSource that overrides EstimatedHeight
public class Source : UITableViewSource
{
public Source(UITableView tableView)
{
// because of a call to ReloadData here...
tableView.ReloadData();
}
// ...this won't be called...
public override nint NumberOfSections(UITableView tableView)
@kentcb
kentcb / RxUIExample.cs
Created October 19, 2015 02:01
ReactiveUI Example
public class MyViewModel : ReactiveObject
{
private readonly ReactiveCommand<object> saveCommand;
private readonly ObservableAsPropertyHelper<string> fullName;
private readonly ObservableAsPropertyHelper<string> initials;
private string firstName;
private string lastName;
private bool showLastNameFirst;
public MyViewModel()
@kentcb
kentcb / RetryWhile.cs
Created November 12, 2015 00:54
RetryWhile
public static class ObservableExtensions
{
public static IObservable<TSource> RetryWhile<TSource>(
this IObservable<TSource> @this,
Func<TSource, bool> predicate)
{
@this.AssertNotNull(nameof(@this));
predicate.AssertNotNull(nameof(predicate));
return Observable
@kentcb
kentcb / InteractionAPIExperiment.cs
Created January 20, 2016 08:17
Playing with Interaction APIs
public class InteractionSource
{
public static readonly InteractionSource Global = new InteractionSource();
private readonly IList<Func<NewInteraction, IObservable<Unit>>> handlers;
public InteractionSource()
{
this.handlers = new List<Func<NewInteraction, IObservable<Unit>>>();
}
@kentcb
kentcb / Logging.cs
Last active June 21, 2016 02:17
Quick and dirty logging
namespace Logging
{
using System;
using System.Diagnostics;
using System.Threading;
public static class Log
{
public static Action<string> LogSink
{
@kentcb
kentcb / ReactiveContentViewBase.cs
Created July 14, 2016 00:48
A base class for XF Reactive views in lieu of a fix for https://github.com/reactiveui/ReactiveUI/issues/1133
namespace ReactiveUI.XamForms
{
using System;
using System.ComponentModel;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using Xamarin.Forms;
// The ReactiveContentView that comes with RxUI does not implement ICanActivate. As such, the activation-for-view-fetcher
public delegate DeviceViewModel DeviceViewModelFactory(IObservable<IDevice> device, IDeviceMetadata deviceMetadata, IObservable<Unit> timer);
public sealed class DeviceViewModel : ReactiveObject
{
public DeviceViewModel(
IObservable<IDevice> device,
IDeviceMetadata deviceMetadata,
IScheduler scheduler,
IObservable<Unit> timer)
{
@kentcb
kentcb / DDSortingRepro.cs
Created July 18, 2016 07:54
Repro of DynamicData sorting problem
public class ItemViewModel : ReactiveObject
{
private readonly string name;
private readonly ObservableAsPropertyHelper<int> sortOrder;
public ItemViewModel(string name, IObservable<int> sortOrder, IScheduler scheduler)
{
this.name = name;
this.sortOrder = sortOrder
.ToProperty(this, x => x.SortOrder, scheduler: scheduler);
@kentcb
kentcb / Sweetblue.log
Last active July 25, 2016 00:48
Log of Sweetblue output
07-25 10:16:20.420 D/btif_config_util(30154): btif_config_save_file(L188): in file name:/data/misc/bluedroid/bt_config.new
07-25 10:16:21.885 D/audio_hw_primary( 1406): disable_audio_route: reset and update mixer path: low-latency-playback
07-25 10:16:21.886 D/audio_hw_primary( 1406): disable_snd_device: snd_device(2: speaker)
07-25 10:16:24.671 D/audio_hw_primary( 1406): out_set_parameters: enter: usecase(1: low-latency-playback) kvpairs: routing=2
07-25 10:16:24.682 D/audio_hw_primary( 1406): select_devices: out_snd_device(2: speaker) in_snd_device(0: none)
07-25 10:16:24.682 D/msm8974_platform( 1406): platform_send_audio_calibration: sending audio calibration for snd_device(2) acdb_id(15)
07-25 10:16:24.682 D/audio_hw_primary( 1406): enable_snd_device: snd_device(2: speaker)
07-25 10:16:24.686 D/audio_hw_primary( 1406): enable_audio_route: apply and update mixer path: low-latency-playback
07-25 10:16:24.806 D/Mono (20193): DllImport attempting to load: '__Internal'.
07-25 10:16:24.806 D/Mono (20193):
@kentcb
kentcb / Layout.cs
Created December 2, 2016 02:48
iOS Auto-layout C# fluent interface
// this code is a heavily modified (and tested) version of https://gist.github.com/praeclarum/6225853
// example usage
this.ContentView.ConstrainLayout(() =>
this.clientNameLabel.Left() == this.ContentView.Left() + Layout.StandardSuperviewSpacing &&
this.clientNameLabel.Top() == this.ContentView.Top() + Layout.StandardSiblingViewSpacing &&
this.createdLabel.Left() == this.clientNameLabel.Right() + Layout.StandardSiblingViewSpacing &&
this.createdLabel.CenterY() == this.ContentView.CenterY() &&
this.createdLabel.Right() == this.ContentView.Right() - Layout.StandardSuperviewSpacing &&
this.referenceLabel.Left() == this.clientNameLabel.Left() &&