Skip to content

Instantly share code, notes, and snippets.

View vpatryshev's full-sized avatar
💭
married

Vlad Patryshev vpatryshev

💭
married
View GitHub Profile
@vpatryshev
vpatryshev / docker-osx-shared-folders.rst
Created June 2, 2024 00:18 — forked from graydon/docker-osx-shared-folders.rst
How to share folders with docker containers on OSX

How to share a folder with a docker container on OSX

Mounting shared folders between OSX and the docker container is tricky due to the intermediate boot2docker VM. You can't use the usual docker -v option as the docker server knows nothing about the OSX filesystem - it can only mount folders from the boot2docker filesystem. Fortunately, you can work around this using SSHFS.

@vpatryshev
vpatryshev / findjdks.sh
Created January 17, 2024 19:44
Find JDKs that will work with your Scala project
#!/bin/bash
Try all available JDKs to find which one works for your Scala and sbt.
clear && printf '\e[3J'
function testWith(){
java=$1
echo Y | sdk install java "$java"
sdk use java "$java"
sbt clean test package 2>$java.log && rm $java.log && return 0 || return 1
@vpatryshev
vpatryshev / NotaMonad.scala
Created November 13, 2022 17:33
sample applicative functor in Scala that is not a monad
/**
* An example of a polynomial applicative functor `1+X×X` build from two monads, 1+ and X×X, and
* which is not a monad.
*
* Idea: https://stackoverflow.com/questions/49742377/is-data-poe-a-empty-pair-a-a-a-monad/49742857#49742857
*/
object NotMonad {
sealed trait SquarePlusOne[+A] {
def map[B](f: A => B): SquarePlusOne[B]
}
@vpatryshev
vpatryshev / ImplicitConverter.scala
Created January 31, 2022 13:08
How to build an implicit generic converter
class Test extends AnyFlatSpec with Matchers {
"transformer" should "work" in {
// source: https://contributors.scala-lang.org/t/ability-to-force-the-caller-to-specify-a-type-parameter-for-a-polymorphic-method/2116/26
sealed trait NotNothing[-T]
object NotNothing {
@implicitAmbiguous("inst() method needs a generic parameter type, which is missing")
implicit val nothingIsNothing = new NotNothing[Nothing]{}
implicit def notNothing[T] = new NotNothing[T] {}
@vpatryshev
vpatryshev / CovarianceAndContravariance.scala
Last active August 24, 2021 03:15
## Covariance and Contravariance Illustrated
import Experiments_1.Q2
object Experiments_1:
// class Q1[+T]:
// def enqueue(x: T): Unit = println(s"Q1 enqueued $x")
// val x1: Q1[Any] = new Q1[Int]
class Q2[-T]:
def enqueue(x: T): Unit = println(s"Q2 enqueued $x")
@vpatryshev
vpatryshev / gist:dfdee1b6b0813c8bed5b0917df732e8c
Created March 1, 2021 22:02
Simplify via readable implicit
// Before
def buildItem(eob:EOB)(props: Props): Result[EOB_item] = {
implicit val empty: String = "" // weird
for (sDate <- props valueOf DateOfServicePerItem;
date <- DateFormat("MM/dd/yyyy").parseCurrent(sDate);
description <- props valueOf ProcedureDescription;
sBilled <- props valueOf BilledPerItem;
billed <- dollars(sBilled);
@vpatryshev
vpatryshev / EnvHacker.scala
Last active August 4, 2021 12:29 — forked from jaytaylor/EnvHacker.scala
Setting environment variables in Scala JVM
import java.util.{Collections, Map => JavaMap}
import scala.collection.JavaConverters._
trait EnvHacker {
/**
* Portable method for setting env vars on both *nix and Windows.
* @see http://stackoverflow.com/a/7201825/293064
*/
def setEnv(newEnv: Map[String, String]): Unit = {
try {
@vpatryshev
vpatryshev / binary tree inorder
Created April 27, 2016 16:04
implementation of inorder scan of a binary tree
case class BT[T](left: Option[BT[T]], value: T, right: Option[BT[T]]);
def inorder[T](t:BT[T], out: T=>Unit): Unit = {
val stack: mutable.Stack[(Boolean, BT[T])] = new mutable.Stack[(Boolean, BT[T])]()
def p(n: BT[T]) = stack.push((false, n))
p(t)
while (!stack.isEmpty) {
(stack.pop() match {
case (true, top) =>
out(top.value)
@vpatryshev
vpatryshev / package.scala
Created December 16, 2015 06:10 — forked from zraffer/package.scala
a few operations with functors
package object types {
import scala.language.reflectiveCalls
import scala.language.higherKinds
// quantifiers aka (co)ends
type Forall[+F[_]] = { def apply[X]: F[X] }
type Exists[+F[_]] = F[_]
// basic categorical notions
### Keybase proof
I hereby claim:
* I am vpatryshev on github.
* I am vpatryshev (https://keybase.io/vpatryshev) on keybase.
* I have a public key whose fingerprint is F7CC C6E9 59DF 55AF 2BE7 676B 31F4 2673 9622 4C88
To claim this, I am signing this object: