Skip to content

Instantly share code, notes, and snippets.

mr5z / BaseCommand.cs
Created Jan 13, 2021
DelegateCommand wrapper
View BaseCommand.cs
public class BaseCommand : DelegateCommand
public double InvocationDelayInSeconds { get; set; }
private DateTime lastInvokeTime = DateTime.MinValue;
private readonly Func<bool> canExecute;
public BaseCommand(
Action executeAction,
View AsyncGotcha.cs
// Correct
public static async Task<string> StreamToString(Stream stream)
using var reader = new StreamReader(stream);
return await reader.ReadToEndAsync();
// Incorrect
public static Task<string> StreamToString(Stream stream)
View TestConsole.cs
using System;
using System.Threading;
using System.Threading.Tasks;
namespace TestCsharpConsole
public class Program
public static async Task Main(string[] args)
View ConsoleHelper.cs
using System;
using System.Runtime.InteropServices;
namespace TestCsharpConsole
public static class ConsoleHelper
public static void Write(int left, int top, string text, ConsoleColor color = ConsoleColor.White)
Console.ForegroundColor = color;
mr5z / GameActivity.kt
Created Dec 6, 2020
DotInCave main logic
View GameActivity.kt
package com.nkraft.dotincave.activities
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.SystemClock
import android.os.Vibrator
import android.util.Size
View dotincave1.cs
// Cave
public partial class Cave
public int Id { get; set; }
public int AuthorId { get; set; }
public int MapId { get; set; }
View CaveDto.cs
public class CaveDto
public int Id { get; set; }
public string Name { get; set; }
public UserDto Author { get; set; }
public List<PathDto> Path { get; set; }
public MapDto Map { get; set; }
public DateTimeOffset DateCreated { get; set; }
public DeviceType DeviceOrigin { get; set; }
public long Duration { get; set; }
View wtf.cs
public async Task<ActionResult<Cave>> PostCave([FromBody]CaveDto cave)
context.Point.Add(new Point
context.Path.Add(new Path
View IsThisValid.cs
from cave in context.Cave
join user in context.User on cave.AuthorId equals user.Id
join map in context.Map on cave.Id equals map.CaveId
let score =
from score in context.Score
where score.CaveId == cave.Id && score.UserId == user.Id
select score.MaxScore
let paths =
mr5z / CaveAndPoints.cs
Last active Oct 29, 2020
Convert loop in a single query
View CaveAndPoints.cs
foreach(var entry in caveQuery)
var pointQuery =
from path in context.Path
join cave in context.Cave on path.CaveId equals cave.Id
join point in context.Point on path.Id equals point.PathId
where cave.Id == entry.Id
select new PointDto
X = point.X,