Skip to content

Instantly share code, notes, and snippets.

View mikla's full-sized avatar

Artsiom Miklushou mikla

View GitHub Profile
@mikla
mikla / compose.yml
Created February 4, 2020 11:43
cassandra cluster docker compose
services...
cassandra-seed:
container_name: cassandra-seed-node
image: cassandra:3.11.0
ports:
- "9042:9042" # Native transport
- "7199:7199" # JMX
- "9160:9160" # Thrift clients
@mikla
mikla / toward-scalajs-1.md
Last active April 9, 2020 15:56
Toward Scala.js 1 Libraries status
@mikla
mikla / 0.gv.svg
Last active April 28, 2020 08:18
scalacss toward Scala.js 1.0, dependencies
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mikla
mikla / Discipline.scala
Created September 28, 2019 14:22
checAll for
mport org.scalacheck.Properties
import org.scalatest.FunSuiteLike
import org.scalatest.prop.Checkers
trait Discipline extends Checkers { self: FunSuiteLike =>
def checkAll(name: String, ruleSet: Laws#RuleSet): Unit = {
for ((id, prop) ← ruleSet.all.properties)
test(name + "." + id) {
@mikla
mikla / KeyPresser.scala
Created June 13, 2019 22:03
App that presses keys randomly.
import java.awt.Robot
import java.awt.event.{InputEvent, KeyEvent}
import scala.util._
object KeyPresser extends App {
import KeyEvent._
val robot = new Robot()

Explaining Miles's Magic

Miles Sabin recently opened a pull request fixing the infamous SI-2712. First off, this is remarkable and, if merged, will make everyone's life enormously easier. This is a bug that a lot of people hit often without even realizing it, and they just assume that either they did something wrong or the compiler is broken in some weird way. It is especially common for users of scalaz or cats.

But that's not what I wanted to write about. What I want to write about is the exact semantics of Miles's fix, because it does impose some very specific assumptions about the way that type constructors work, and understanding those assumptions is the key to getting the most of it his fix.

For starters, here is the sort of thing that SI-2712 affects:

def foo[F[_], A](fa: F[A]): String = fa.toString
@mikla
mikla / PlainStringRecord.scala
Last active May 25, 2017 07:25
Type class that extracts information about all fields into Map[String, String].
/**
* Type class that extracts information about all fields into Map[String, String].
* It's uses `PlainStringRecordValue` instances for particular type of the field to obtain string representation.
* @tparam T
*/
@typeclass trait PlainStringRecord[T] {
def plainStringRecord(t: T): Map[String, String]
}
@mikla
mikla / AffectsUser.scala
Last active May 25, 2017 07:23
Type class for extracting field with UserId type from case class.
import shapeless.{:+:, ::, CNil, Coproduct, Generic, HList, HNil, Inl, Inr}
import simulacrum.typeclass
import language.implicitConversions
case class UserId(value: UUID) extends AnyVal
/**
* Type class for extracting field with UserId type from case class.
*
* @tparam T
#include <string.h>
#include <stdio.h>
void func(char *arg1) {
int authenticated = 0;
char buffer[4];
strcpy(buffer, arg1);
if (authenticated) {
printf("Authenticated via buffer overflow");
}
@mikla
mikla / SuiteRetries.scala
Last active March 7, 2017 11:31
Rerun whole scalatest suite on test fail.
import org.scalatest._
import org.scalatest.events._
import org.slf4j.Logger
trait SuiteRetries extends SuiteMixin {
this: Suite =>
def logger: Logger
private def runWithCustomReporter(testName: Option[String], args: Args) = {