Skip to content

Instantly share code, notes, and snippets.

View mr5z's full-sized avatar
🎯
Focusing

mark mr5z

🎯
Focusing
View GitHub Profile
@mr5z
mr5z / CaveAndPoints.cs
Last active October 29, 2020 07:08
Convert loop in a single query
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,
@mr5z
mr5z / Ko
Last active October 23, 2020 11:34
weird
// This one throws
buildColorPicker().apply {
enableAutoClose()
setCallback { color ->
model.map.color = color
mapView.invalidate()
}
show()
}
@mr5z
mr5z / KotlinSucks.kt
Created October 22, 2020 11:26
ugly kotlin
items.forEach { item ->
for(map in mapList) {
if (map.id == item.mapId) {
map.score = item.score
break
}
}
}
@mr5z
mr5z / mp4-gif.sh
Last active October 27, 2020 16:09
Create optimized GIF
ffmpeg -ss 0 -t 70 -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif
# the 0 -t 70 means range in seconds
#ffmpeg -i input.mp4 -pix_fmt rgb8 output.gif
@mr5z
mr5z / CustomTimer.kt
Last active January 30, 2023 15:24
Resumable CountdownTimer
class CustomTimer(private val millisInFuture: Long, private val countDownInterval: Long) {
private var millisUntilFinished: Long = millisInFuture
private var timer = InternalTimer(this, millisInFuture, countDownInterval)
private var isRunning = false
var onTick: ((millisUntilFinished: Long) -> Unit)? = null
var onFinish: (() -> Unit)? = null
private class InternalTimer(
@mr5z
mr5z / xf_stuffs.cs
Last active September 29, 2020 09:33
bla bla
public static BindableProperty <insert the object nameof(Property) here> + Property = CreateProperty<T>(nameof(<insert the object nameof(Property) here>));
public T <insert the object nameof(Property) here>
{
get => (T)GetValue(<insert the object nameof(Property) here> + Property);
set => SetValue(<insert the object nameof(Property) here> + Property, value);
}
// TODO put this under Utility folder
public static BindableProperty CreateProperty<T>(string propertyName, T defaultValue = default, BindingMode mode = BindingMode.TwoWay)
@mr5z
mr5z / get_profit_data2.json
Created September 27, 2020 22:16
bla bla
[{"i":1,"j":2,"buy":1,"sell":5,"profit":4,"id":0,"children":[{"i":3,"j":4,"buy":3,"sell":6,"profit":3,"id":5,"children":[]},{"i":3,"j":5,"buy":3,"sell":4,"profit":1,"id":6,"children":[]}]},{"i":1,"j":3,"buy":1,"sell":3,"profit":2,"id":1,"children":[]},{"i":1,"j":4,"buy":1,"sell":6,"profit":5,"id":2,"children":[]},{"i":1,"j":5,"buy":1,"sell":4,"profit":3,"id":3,"children":[]},{"i":2,"j":4,"buy":5,"sell":6,"profit":1,"id":4,"children":[]},{"i":3,"j":4,"buy":3,"sell":6,"profit":3,"id":5,"children":[]},{"i":3,"j":5,"buy":3,"sell":4,"profit":1,"id":6,"children":[]}]
@mr5z
mr5z / get_profit_data.json
Created September 27, 2020 22:07
bla bla
[{"i":0,"j":1,"buy":1,"sell":2,"profit":1,"id":0,"children":[{"i":2,"j":3,"buy":3,"sell":4,"profit":1,"id":7,"children":[]},{"i":2,"j":4,"buy":3,"sell":5,"profit":2,"id":8,"children":[]},{"i":3,"j":4,"buy":4,"sell":5,"profit":1,"id":9,"children":[]}]},{"i":0,"j":2,"buy":1,"sell":3,"profit":2,"id":1,"children":[{"i":3,"j":4,"buy":4,"sell":5,"profit":1,"id":9,"children":[]}]},{"i":0,"j":3,"buy":1,"sell":4,"profit":3,"id":2,"children":[]},{"i":0,"j":4,"buy":1,"sell":5,"profit":4,"id":3,"children":[]},{"i":1,"j":2,"buy":2,"sell":3,"profit":1,"id":4,"children":[{"i":3,"j":4,"buy":4,"sell":5,"profit":1,"id":9,"children":[]}]},{"i":1,"j":3,"buy":2,"sell":4,"profit":2,"id":5,"children":[]},{"i":1,"j":4,"buy":2,"sell":5,"profit":3,"id":6,"children":[]},{"i":2,"j":3,"buy":3,"sell":4,"profit":1,"id":7,"children":[]},{"i":2,"j":4,"buy":3,"sell":5,"profit":2,"id":8,"children":[]},{"i":3,"j":4,"buy":4,"sell":5,"profit":1,"id":9,"children":[]}]
@mr5z
mr5z / ContainerExtesion.cs
Created September 22, 2020 10:01
IoC extension
using System;
using Prism.Ioc;
namespace ProjectName
{
// NOTE
// We should not register services that falls under these categories:
// 1. Implementation is platform-specific
// 2. Implementation requires a certain dependency which doesn't caters all use cases, e.g: Crash Analytics Service
@mr5z
mr5z / problem18.cpp
Last active September 22, 2020 09:37
Part of the project euler#18
#include <iostream>
#include <cstdint>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <exception>
#include <climits>
template<class T>