Skip to content

Instantly share code, notes, and snippets.

@mr5z
mr5z / neil.php
Last active Mar 26, 2021
1k lang
View neil.php
<html>
<head>
<style>
#customers {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}
#customers td, #customers th {
@mr5z
mr5z / AdaptiveCommand.cs
Created Mar 2, 2021
Smart and Non-async/Async implementation of ICommand
View AdaptiveCommand.cs
// You need Prism though :)
public class AdaptiveCommand : DelegateCommand
{
private const double DefaultInvocationDelay = 0.7;
public double InvocationDelayInSeconds { get; set; }
private DateTime lastInvokeTime = DateTime.MinValue;
private readonly Func<bool>? canExecute;
View GetCaves.cs
// 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 Jan 17, 2021
Longest way to implement extended hamming code error detection. It doesn't even have a correction capability.
View crap.js
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 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
mr5z / GameActivity.kt
Created Dec 6, 2020
DotInCave main logic
View GameActivity.kt
package com.nkraft.dotincave.activities
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.graphics.*
import android.os.Bundle
import android.os.SystemClock
import android.os.Vibrator
import android.util.Size
View dotincave1.cs
// 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)]