Skip to content

Instantly share code, notes, and snippets.

View mr5z's full-sized avatar
🎯
Focusing

mark mr5z

🎯
Focusing
View GitHub Profile
@mr5z
mr5z / 1902_ks3.cs
Last active October 30, 2019 06:38
// Don't
public void DoSomething()
{
if (startsWithOneThing)
{
if (iDontKnowWhy)
{
if (itDoesntEvenMatter && howHardItry)
{
@mr5z
mr5z / 1902_ks4.cs
Last active October 30, 2019 06:39
public void DoSomething()
{
if (!startsWithOneThing)
return;
if (iDontKnowWhy)
{
IDontKnowWhy(1);
}
else if (itDoesEvenMatter)
@mr5z
mr5z / 1902_ks5.cs
Last active October 30, 2019 04:30
private List<TimeSpan> queueForward = new List<TimeSpan>();
private CancellationTokenSource ctsForward;
private void Forward()
{
var steps = TimeSpan.FromSeconds(StepsInSeconds);
queueForward.Add(entry);
try
{
ctsForward?.Cancel();
public class User
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string DisplayName { get; set; }
private void DoSomething()
{
if (string.IsNullOrEmpty(FirstName))
DisplayName = string.Empty;
@mr5z
mr5z / 1902_ks7.cs
Last active October 30, 2019 04:51
// Don't
public class FileImageSource
{
public string File { get; set; }
}
var source = new FileImageSource();
source.File = "ic_about";
@mr5z
mr5z / 1902_ks8.cs
Last active October 30, 2019 06:31
// Don't
private void DoSomething()
{
var a=1+1/2-3;
@mr5z
mr5z / 1902_ks9.cs
Last active October 30, 2019 05:43
private async Task<DataResponse<TResult>> HandleNonSuccessStatusCodes<TResult>(HttpResponseMessage response)
{
return response.StatusCode switch
{
HttpStatusCode.BadRequest => await OnBadRequest(response),
HttpStatusCode.NotFound => await OnNotFound(response),
_ => null
};
}
@mr5z
mr5z / UserDisplayListPageViewModel.cs
Last active November 18, 2019 09:11
Event Sourcing Implementation
public class EventSourcingPageViewModel : ViewModel
{
private readonly IEventSourcing eventSourcing;
private readonly IToastService toastService;
// Below is the usual approach
// where we add each services.
// but since we're using EventSourcing, we don't need it anymore
// private readonly IAccountService;
@mr5z
mr5z / SourceEventArgs.cs
Created November 20, 2019 10:05
too long
public interface ISourceEventArgs<out T>
{
string EventName { get; }
EventSourceStatus Status { get; set; }
PreferredSourceType Type { get; set; }
DateTimeOffset Timestamp { get; }
T Data { get; }
bool IsSuccess { get; }
}
@mr5z
mr5z / StreamDeserialize.cs
Last active March 4, 2020 10:24
You should use this
private async Task StreamDeserialize(HttpResponseMessage response, Guid id, CancellationToken cancellationToken)
{
// TODO dynamically change the buffer size base on device specification and connection status
var content = response.Content;
long contentLength = content.Headers.ContentLength ?? 0;
DownloadProgress?.Invoke(this, new DownloadEventArgs(id, SerializeState.Pending));
using var stream = await content.ReadAsStreamAsync().ConfigureAwait(false);
var totalBytesRead = 0;
var buffer = new byte[DownloadBufferSize];
var bytesRead = 0;