Skip to content

Instantly share code, notes, and snippets.

View pakoito's full-sized avatar
🎨
painting boxes

Paco pakoito

🎨
painting boxes
View GitHub Profile
@pakoito
pakoito / ContextN.kt
Last active February 13, 2022 15:24
ContextN
inline fun <A, T> withN(t: T, f: context(T) () -> A) =
with(t) { f() }
inline fun <A, T, U> withN(t: T, u: U, f: context(T, U) () -> A) =
with(t) { with(u) { f() } }
inline fun <A, T, U, V> withN(t: T, u: U, v: V, f: context(T, U, V) () -> A) =
with(t) { with(u) { with(v) { f() } } }
inline fun <A, T, U, V, W> withN(t: T, u: U, v: V, w: W, f: context(T, U, V, W) () -> A) =
data class User(
val name: String
)
interface GetUserService {
fun Id.fetchUser(): User
}
context(Context)
fun makeGetUserService(): GetUserService = object : GetUserService {
@pakoito
pakoito / forge.cmd
Last active January 11, 2022 17:35
MTG Forge Windows Launcher
::@echo off
pushd %~dp0
java -version 1>nul 2>nul || (
echo no java installed
popd
exit /b 2
)
for /f tokens^=2^ delims^=.-_^+^" %%j in ('java -fullversion 2^>^&1') do set "jver=%%j"
pdfx() {
name=$(basename $3 .pdf)
for i in {0..$(expr $(vipsheader -f pdf-n_pages $3) - 1)}; do
noglob vips copy $3[dpi=$1,page=$i] $(realpath $2)/$name-$(expr $i + 1)@$1.jpg;
done
}
# cmd dpi outdir infile
# pdfx 300 ./out mypdf.pdf
private fun loggedInMenuUi(menu: Menu, rootView: View, checkoutCartStream: Stream<Bla>, startActivity: () -> Unit) {
val alertMenuItem = menu.findItem(R.id.activity_main_alerts_menu_item)
val rootView = (alertMenuItem.actionView as FrameLayout).apply {
setOnClickListener {
startActivity()
}
}
val redCircle: FrameLayout = rootView.findViewById(R.id.view_alert_red_circle)
when (info) {
null -> {
return unauthorized()
}
else -> {
val validInfo = validator.validateInfo(info)
when (validInfo) {
is Either.Right -> {
if (!validInfo.b.authorised) {
const Day = ({ get, left, right }) => {
const map = f => Day ({
get: f (extract()),
left, right
})
const extend = f =>
Day ({
get: (left, right) => f (Day ({ get, left, right })),
@pakoito
pakoito / Test.kt
Created April 8, 2018 11:24
Applicatives, Functors and Monads using Kotlin and Arrow
import arrow.core.*
import arrow.data.k
import arrow.syntax.applicative.tupled
import arrow.syntax.functor.map
import arrow.typeclasses.binding
typealias IntFunction = (Int) -> Int
fun IntFunction.map(g: IntFunction) = { it: Int -> this(g(it)) }
extern crate specs;
use specs::Component;
use specs::VecStorage;
use specs::System;
use specs::WriteStorage;
use specs::ReadStorage;
use specs::World;
use specs::DispatcherBuilder;
use specs::RunNow;