Skip to content

Instantly share code, notes, and snippets.

@arturaz
arturaz / gist:67d573b080798db265958ef48a912399
Created March 30, 2023 14:41
Scala compiler error on 3.3.1-RC1-bin-20230328-5c2efc5-NIGHTLY
scala.MatchError: ContextualMethodType(List(x$3), List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class app)),object data),LogCorrelationId)), AppliedType(TypeRef(ThisType(TypeRef(NoPrefix,module class util)),class Either),List(TypeRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),Predef),String), AppliedType(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),Option),List(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class data)),object steam),SteamClientId)))))) (of class dotty.tools.dotc.core.Types$CachedMethodType)
at dotty.tools.dotc.core.tasty.TreePickler.pickleNewType(TreePickler.scala:294)
at dotty.tools.dotc.core.tasty.TreePickler.pickleType(TreePickler.scala:162)
at dotty.tools.dotc.core.tasty.TreePickler.pickleTree(TreePickler.scala:625)
at dotty.tools.dotc.core.tasty.TreePickler.pickleTpt(TreePickler.scala:319)
at dotty.tools.dotc.core.tasty.TreePickler.pickleDef(TreePickler.scala:338)
at dotty.tools.dotc.core.tasty.TreePickl
diff --git a/quill-sql/src/main/scala/io/getquill/util/Format.scala b/quill-sql/src/main/scala/io/getquill/util/Format.scala
index 31e8e7e1..040690ad 100644
--- a/quill-sql/src/main/scala/io/getquill/util/Format.scala
+++ b/quill-sql/src/main/scala/io/getquill/util/Format.scala
@@ -120,7 +120,9 @@ object Format {
linesTrimmedLast.mkString("\n")
val formatted =
- Try {
+ // We can't use `Try` here because it won't catch linking errors as those are considered
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using UnityEngine;
using Debug = UnityEngine.Debug;
public unsafe class TestInVsPointer : MonoBehaviour
{
// 8 * 8 = 64 bytes
@arturaz
arturaz / CallbacksSubscribable.cs
Last active December 20, 2022 15:14
A version of the Photon Quantum DebugDraw commands that last for a duration rather than a single frame only.
using System;
using FPCSharpUnity.core.dispose;
using Quantum.Game.extensions;
namespace Quantum;
/// <summary>
/// <para>Read-only interface for <see cref="CallbackDispatcher"/>.</para>
///
/// <para>
@arturaz
arturaz / plutus.scala
Created December 3, 2022 07:47
Parser for plutus transactions PDF
val src = """
Card Transaction
CRV*UAB ABUNDO, Vilnius, LT CD 0108 2022/01/12, 18:26 - €1.5
"""
import java.time.LocalDateTime
val Re = """^(.*?)(\d{4})/(\d\d)/(\d\d),\s*(\d\d):(\d\d)\s*(-)?\s*€([\d\\.]+)$""".r
val amounts = src.linesIterator.sliding(2).withPadding("").flatMap { case Seq(prevLine, line) =>
if (
line.contains("Card Deposit")
@arturaz
arturaz / FuncK.cs
Last active December 2, 2022 19:51
Practical demonstration of config diffing with higher kinded types in C#
using System;
using JetBrains.Annotations;
namespace FPCSharpUnity.core.functional.higher_kinds;
/// <summary>
/// As <see cref="Func{A,B}"/>, but transforms the functor W1[_] to W2[_], instead of transforming the value.
/// </summary>
[PublicAPI] public interface FuncK<W1, W2> {
HigherKind<W2, A> apply<A>(HigherKind<W1, A> value);
@arturaz
arturaz / Bounds1.scala
Created October 10, 2022 18:25
Code for "Scala =:= and implicits demystified " video (https://www.youtube.com/watch?v=4jrHAmKx7YE)
package app.implicit_constraints
object Bounds1 {
case class Container[A](a: A)
implicit class IntContainerExtensions(container: Container[Int]) {
def addWithExtension(other: Int): Int = container.a + other
}
val intContainer: Container[Int] = Container(5)
@arturaz
arturaz / jsonb.scala
Created October 5, 2022 17:42
Quill encoder/decoder with play-json
def jsEncoder[A](implicit w: Writes[A @@ SerializedInDB]): Encoder[A] = encoder[A](
java.sql.Types.OTHER,
(index: Index, value: A, row: PrepareRow) =>
row.setObject(index, writeJS(value), java.sql.Types.OTHER)
)
def jsOptEncoder[A](implicit w: Writes[A @@ SerializedInDB]): Encoder[Option[A]] = encoder[Option[A]](
java.sql.Types.OTHER,
(index: Index, maybeValue: Option[A], row: PrepareRow) => {
val json = maybeValue.fold2(null, a => writeJS(a)(w))
// See Utilities.SetWindowTitle.cs for explanation
#if UNITY_EDITOR_WIN || (UNITY_STANDALONE_WIN && !UNITY_EDITOR)
using System;
using System.Runtime.InteropServices;
using FPCSharpUnity.unity.Logger;
using FPCSharpUnity.unity.Utilities;
using GenerationAttributes;
using FPCSharpUnity.core.exts;
using FPCSharpUnity.core.log;
using static FPCSharpUnity.unity.win32_api.Win32API;
@arturaz
arturaz / AbilityTargetData.partials.cs
Created October 18, 2021 10:16
Proposal/example for Quantum union generation
// ReSharper disable all
using System;
namespace Quantum
{
public partial struct AbilityTargetData
{
public static AbilityTargetData newCharacter(EntityRefCharacter _character)
{
var data = default(AbilityTargetData);