Skip to content

Instantly share code, notes, and snippets.

@arturaz
arturaz / gist:275a20a4eaa8e1563c46fd7acd143eab
Last active January 29, 2024 12:46
ALine XBox One build shader compilation failure for Unity
### Unity 2020.3.40f1
### -unityBuildTarget "GameCoreXboxOne"
[build|2/9/2023 8:42:11 AM|00:07:45.1588570] Compiling shader "Hidden/ALINE/Surface" pass "Pass 2" (fp)
[build|2/9/2023 8:42:11 AM|00:07:45.1591019] 1 / 1 variants left after stripping, processed in 0.00 seconds
[build|2/9/2023 8:42:11 AM|00:07:45.1593342] starting compilation...
[build|2/9/2023 8:42:11 AM|00:07:45.1596597] finished in 0.02 seconds. Local cache hits 0 (0.00s CPU time), remote cache hits 0 (0.00s CPU time), compiled 1 variants (0.02s CPU time), skipped 0 variants
[build|2/9/2023 8:42:11 AM|00:07:45.1599886] Serialized binary data for shader Hidden/ALINE/Surface in 0.00s
[build|2/9/2023 8:42:11 AM|00:07:45.1603637] gamecore_xboxone (total internal programs: 0, unique: 0)
[build|2/9/2023 8:42:11 AM|00:07:45.1607149] Shader error in 'Hidden/ALINE/Surface': unknown type name 'sampler2D'; did you mean 'sampler'? at 11(1) (on gamecore_xboxone)
@arturaz
arturaz / Functions.cs
Created December 19, 2013 08:18
Backporting .NET 4.5 functions to unity
/**
* Co & contravariant definitions of Action and Func
*
* Generated with scala:
*
(1 to 22).foreach { i =>
val r = 1 to i
val types = r.map(n => s"in P$n").mkString(", ")
val args = r.map(n => s"P$n p$n").mkString(", ")
package app.webclient_prelude.utils
import com.raquo.airstream.core.Signal
import com.raquo.airstream.split.SplittableSignal
import com.raquo.airstream.state.Var
/** Like [[Var.zoom]] but is not required to have an [[com.raquo.airstream.ownership.Owner]]. */
trait UpdatableSignal[A] { self =>
/** The [[Signal]] which is most likely mapped from a [[Var]]. */
@arturaz
arturaz / Actor.scala
Last active November 8, 2023 09:50
Simple Actor implementation using cats effect and FS2
package app.utils
import cats.effect.Concurrent
import cats.effect.kernel.{DeferredSink, DeferredSource}
import fs2.concurrent.Channel
/**
* An actor that processes messages one at a time.
*/
trait Actor[F[_], Message] {
@arturaz
arturaz / EchoMacro.scala
Created November 2, 2023 10:00
Implementation of an echo macro in Scala 3
extension [A](inline value: A) {
/**
* Echoes the value of the given expression.
*
* Example:
* {{{
* val foo = "Hi"
* foo.echo // "foo=Hi"
* }}}
*/
@arturaz
arturaz / CommandLineArgsParser.scala
Last active July 10, 2023 20:19
A parser written with cats-parse that turns a string into a list of command line arguments, similar to how a shell would do it.
package app.utils
import cats.parse.{Parser as P, Parser0 as P0}
import cats.syntax.show.*
import scala.util.control.NonFatal
/**
* A parser that turns a string into a list of command line arguments, similar to how a shell would do it.
*
package app.data
import cats.effect.kernel.Resource
import cats.effect.std.Semaphore
import cats.effect.{Concurrent, IO, Ref, Sync, SyncIO}
import cats.implicits.{toFlatMapOps, toFunctorOps}
import cats.{Applicative, Functor, Monad, ~>}
/**
* [[Ref]] of [[A]] which relies on locking instead of compare-and-swap to provide concurrent access data safety.
@arturaz
arturaz / async.rs
Created May 5, 2023 08:58
Rust: async_trait + pin_project
use std::{pin::Pin, future::Future, task::{Context, Poll}};
use async_trait::async_trait;
use pin_project::pin_project;
use std::sync::Arc;
#[async_trait]
pub trait MyAsyncTrait: Send + Sync + Clone {
async fn my_async_fn(&self);
}
@arturaz
arturaz / IO.cs
Last active April 19, 2023 12:48
Stack safe implementation of an IO monad in C#
using System;
using JetBrains.Annotations;
using pzd.lib.data;
using pzd.lib.exts;
namespace pzd.lib.functional {
/// <summary>
/// Allows encapsulating side effects and composing them.
/// </summary>
// ReSharper disable once UnusedTypeParameter
@arturaz
arturaz / free_monad.cs
Last active April 10, 2023 09:01
Free Monad implementation in C# (CSharp)
using System;
namespace main {
// Modeled against
// https://medium.com/@olxc/free-monads-explained-pt-1-a5c45fbdac30
//
// Higher kind simulation from https://medium.com/@johnmcclean/simulating-higher-kinded-types-in-java-b52a18b72c74
static class Id {
public struct W {}