Skip to content

Instantly share code, notes, and snippets.

View plokhotnyuk's full-sized avatar

Andriy Plokhotnyuk plokhotnyuk

View GitHub Profile
@nadavwr
nadavwr / .gitpod.Dockerfile
Created May 28, 2020 15:18
GitPod Metals setup
FROM gitpod/workspace-full
USER gitpod
RUN brew install coursier/formulas/coursier
ENV COURSIER_CACHE /workspace/.coursier/cache/v1
RUN cs setup --yes --jvm 14 --apps sbt-launcher,scala,scalafmt,mill,mill-interactive
@jodersky
jodersky / pickler.scala
Created May 26, 2020 17:57
Simple ujson-based pickler using Dotty typeclass derivation
import scala.deriving._
import scala.compiletime.{erasedValue, summonInline}
// super primitive (but composable via typeclass derivation) JSON reader
trait Reader[A] {
def read(json: ujson.Value): A
}
object Reader {
given Reader[Int] = new Reader[Int] {

CockroachDB and Docker Compose

This is the first in a series of tutorials on CockroachDB and Docker Compose

  • Information on CockroachDB can be found here.
  • Information on Docker Compose can be found here
  1. Install Docker Desktop

Because we already have an official CockroachDB docker image, we will use that in our docker-compose.yml file. We recommend you use one of the current tags instead of latest.

@dholtz
dholtz / CustomArgMsg.scala
Last active December 15, 2019 21:02
Sendgrid Webhook Event Json Parsing
final case class CustomArgMsg(key: String, value: String, trackable: Boolean)

Here's an error that I got spuriously but rerunning the compilation made it go away.

[E] [E1] config/src/main/scala-2.11-13/bloop/config/ConfigCodecs.scala:119:42
[E]      Cannot evaluate a parameter of the 'make' macro call for type 'bloop.config.Config.JvmConfig'. It should not depend on code from the same compilation module where the 'make' macro is called. Use a separated submodule of the project to compile all such dependencies before their usage for generation of codecs. Cause:
[E]      java.lang.AssertionError: assertion failed: pkgClass = package <root>, sym = package com, existing = package com (depth=0)
[E]      L119:     JsonCodecMaker.make[Config.JvmConfig](CodecMakerConfig.withTransientEmpty(false))
[E]                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[E] config/src/main/scala-2.11-13/bloop/config/ConfigCodecs.scala: L119 [E1]
@witzatom
witzatom / install_polynote.sh
Last active December 18, 2019 10:42
Script to use as a bootstrap step for polynote on EMR
#!/bin/bash
# Requirements (on non-EMR machines):
# * init-ctl or systemctl
# * packages python3.6 python3.6-venv python3.6-dev
# * python3 -V has to be 3.6+ (update-alternatives)
# * JAVA_HOME pointing to java 8 (openjdk or oracle)
# * SPARK_HOME set and included in PATH (see https://polynote.org/docs/01-installation.html)
set -ex
@jvican
jvican / RuntimeUtils.scala
Last active November 22, 2019 16:14
Some Scala code that uses Java APIs present in tools.jar (only JDKs) to programmatically produce a jstack-like thread dump. Useful to debug application and test deadlocks.
object RuntimeUtils {
def requestThreadDump: String = {
// Get the PID of the current JVM process
val selfName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName()
val selfPid = selfName.substring(0, selfName.indexOf('@'))
// Attach to the VM
import com.sun.tools.attach.VirtualMachine
import sun.tools.attach.HotSpotVirtualMachine;
val vm = VirtualMachine.attach(selfPid);
@johnynek
johnynek / dotty_list.scala
Last active September 7, 2024 15:14
Implementation of linked list using dotty features (opaque type, union types, extension methods, type lambda).
// unfortunately
// opaque type Fix[F[_]] = F[Fix[F]]
// won't work (no recursion in opaque type), but this implementation is safe, but scary due to asInstanceOf
object FixImpl {
type Fix[F[_]]
inline def fix[F[_]](f: F[Fix[F]]): Fix[F] = f.asInstanceOf[Fix[F]]
inline def unfix[F[_]](f: Fix[F]): F[Fix[F]] = f.asInstanceOf[F[Fix[F]]]
}

Foreward

This document was originally written several years ago. At the time I was working as an execution core verification engineer at Arm. The following points are coloured heavily by working in and around the execution cores of various processors. Apply a pinch of salt; points contain varying degrees of opinion.

It is still my opinion that RISC-V could be much better designed; though I will also say that if I was building a 32 or 64-bit CPU today I'd likely implement the architecture to benefit from the existing tooling.

Mostly based upon the RISC-V ISA spec v2.0. Some updates have been made for v2.2

Original Foreword: Some Opinion

The RISC-V ISA has pursued minimalism to a fault. There is a large emphasis on minimizing instruction count, normalizing encoding, etc. This pursuit of minimalism has resulted in false orthogonalities (such as reusing the same instruction for branches, calls and returns) and a requirement for superfluous instructions which impacts code density both in terms of size and

@Daenyth
Daenyth / JsoniterSpec.scala
Created April 16, 2019 19:56
Jsoniter fs2 pipe with streaming
import cats.effect.implicits._
import cats.effect.{ConcurrentEffect, ContextShift, IO, Sync}
import cats.implicits._
import com.github.plokhotnyuk.jsoniter_scala.core.{
JsonValueCodec,
scanJsonValuesFromStream,
writeToArray
}
import com.github.plokhotnyuk.jsoniter_scala.macros.{
CodecMakerConfig,