Skip to content

Instantly share code, notes, and snippets.

View mr5z's full-sized avatar
🎯
Focusing

mark mr5z

🎯
Focusing
View GitHub Profile
@mr5z
mr5z / GetCaves.cs
Created January 21, 2021 09:02
get caves
// GET: api/Cave
[HttpGet]
public async Task<ActionResult<IEnumerable<CaveDto>>> GetCave([FromQuery]Pager pager)
{
var caveQuery =
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 =
(
@mr5z
mr5z / crap.js
Last active January 17, 2021 08:58
Longest way to implement extended hamming code error detection. It doesn't even have a correction capability.
function isEven(n) {
return n % 2 == 0;
}
function getColumnSum(column, block, skipFirst) {
return (skipFirst ? 0 : block[column + 0]) +
block[column + 4] +
block[column + 8] +
block[column + 12];
}
@mr5z
mr5z / BaseCommand.cs
Created January 13, 2021 09:53
DelegateCommand wrapper
public class BaseCommand : DelegateCommand
{
public double InvocationDelayInSeconds { get; set; }
private DateTime lastInvokeTime = DateTime.MinValue;
private readonly Func<bool> canExecute;
public BaseCommand(
Action executeAction,
@mr5z
mr5z / AsyncGotcha.cs
Created December 26, 2020 16:05
Aaaa
// 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)
{
@mr5z
mr5z / TestConsole.cs
Created December 17, 2020 15:00
Test console
using System;
using System.Threading;
using System.Threading.Tasks;
namespace TestCsharpConsole
{
public class Program
{
public static async Task Main(string[] args)
{
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;
// Cave
public partial class Cave
{
[Key]
public int Id { get; set; }
[ForeignKey(nameof(Author))]
public int AuthorId { get; set; }
[ForeignKey(nameof(Map))]
public int MapId { get; set; }
[StringLength(50)]
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; }
@mr5z
mr5z / wtf.cs
Created October 29, 2020 10:52
[HttpPost]
public async Task<ActionResult<Cave>> PostCave([FromBody]CaveDto cave)
{
context.Point.Add(new Point
{
});
context.Path.Add(new Path
{
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
).Sum()
let paths =