Skip to content

Instantly share code, notes, and snippets.

View mr5z's full-sized avatar
🎯
Focusing

mark mr5z

🎯
Focusing
View GitHub Profile
@mr5z
mr5z / JsonDeserialize.cs
Created November 26, 2019 09:47
Use this instead of that
private async Task<TModel> JsonDeserialize<TModel>(HttpResponseMessage response)
{
var content = response.Content;
using var stream = await content.ReadAsStreamAsync().ConfigureAwait(false);
using var reader = new StreamReader(stream);
using var json = new JsonTextReader(reader);
return serializer.Deserialize<TModel>(json);
}
@mr5z
mr5z / BackgroundService.cs
Last active December 17, 2019 09:40
Stupid Android
private static Notification CreateNotification(
Context context,
string title,
string description = null,
string largeIcon = null,
string smallIcon = null,
int? progress = null,
bool indeterminate = false,
bool showProgress = true,
bool hasCancelButton = true)
@mr5z
mr5z / sample.ms
Last active January 28, 2020 01:21
M#
package com.msharp.Test
use System.Types
use System.Math
// Defining a constants
config A = 0
config B = 0
config LocalConfig { // enum
@mr5z
mr5z / Flight.cs
Created January 29, 2020 18:11
DDD
namespace Flight
{
class Route
{
public Route(Fix departure, Fix destination)
{
Departure = departure;
Destination = destination;
}
public Fix Departure { get; set; }
@mr5z
mr5z / wiet.asm
Last active February 11, 2020 09:43
wut?
0xdead .classA ; Class B
0xdeae :ToString
0xdeaf mov ax, al
0xdeb0 ...
0xbeef .classB ; Class A
0xbef0 :ToString
0xbef1 mov ax, al
0xbef2 ...
@mr5z
mr5z / point.cs
Created February 14, 2020 00:03
Factory Pattern
// Data
{
"Latitude": 12.123,
"Longitude": 123.13
}
Point(latitude, longitude)
{
Latitude
@mr5z
mr5z / aggregate.cs
Created February 14, 2020 01:37
DDD Aggregates
// Entity
Product(id)
{
Id
Name
Price
}
public static IDictionary<string, object> AsDictionary(this object source, BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance)
{
return source.GetType().GetProperties(bindingAttr).ToDictionary
(
propInfo => propInfo.Name,
propInfo => propInfo.GetValue(source, null)
);
}
private class LayoutObserver(private val view: View, private val callback: (Size) -> Unit) : ViewTreeObserver.OnGlobalLayoutListener {
init {
if (!view.viewTreeObserver.isAlive)
throw IllegalArgumentException("Go fuck yourself")
view.viewTreeObserver.addOnGlobalLayoutListener(this)
}
override fun onGlobalLayout() {
var hasMoved: Boolean = false
get() {
if (initialTouchPosition == null)
return false
if (lastTouchPosition == null)
return false
val xDiff = abs(initialTouchPosition!!.x - lastTouchPosition!!.x)
val yDiff = abs(initialTouchPosition!!.y - lastTouchPosition!!.y)
val epsilon = 0.1
return xDiff > epsilon || yDiff > epsilon