Skip to content

Instantly share code, notes, and snippets.

View rudogma's full-sized avatar

Mikhail Savinov rudogma

View GitHub Profile
import io.circe.Encoder
import io.circe.syntax._
trait HasId[ID] {
def id: ID
}
case class MyEntity(field1: Int, id: String) extends HasId[String]
case class CustomId(field1:Int)
@rudogma
rudogma / 0. Scala-Remote-RUN.md
Last active April 16, 2021 14:57
Easy peasy running scala application on remote machine via ssh #scala #remote #ssh

Description

#Steps

  • You should read some code before using. One day pet code, so don't expect much. But it works, if you know why u need it.
  • Run sbt & then execute pack command for desired project. This will use plugin sbt-pack and copy all dependencies (including every jar for dependend projects described in build.sbt ) to the projectname/target/pack/lib folder
  • Step 1st need to be executed every time when you change list of dependencies (so it's no so often)
  • In idea add Run Configuration - remoterun.Run - and set as argument the real path to object that you want to run on remote machine (for example tests.RemoteTestLauncher - or any other existing object with def main(), or extending App or java static method void main )
  • Run this configuration
  • On every run Idea compile every changes automatically, then this script packs class files for every project you specify, copies it to pack directory, syncing on remote and executing via ssh execute.
  • Has safe check of existence .remoterun fi
@rudogma
rudogma / TestNewtypes.scala
Last active January 1, 2019 17:24
Newtype upgrading for implicits & implicit conversions without imports
import scala.language.higherKinds
import scala.language.implicitConversions
object TestNewtypes extends App {
/**
Changed lines:
type NewType = Newtype[T, Tag0] with superduper.Tag[T, this.type]
def apply[TagIn, Sub, C](c: C)(implicit tagger: Tagger[TagIn, Type, Tag, Sub, C]): NewType = c.asInstanceOf[T with NewType]
@rudogma
rudogma / 01.source.scala
Created September 22, 2017 15:32
Difference between Newtype and TaggedType
-- package.scala --
object Booter extends TaggedType[Int]
type Booter = Booter.Type
implicit class StepOps(val __v:Int) {
def next:Step = Step @@ (__v + 1)
def +(v2:Int):Step = Step @@ (__v + v2)
}
object Step extends NewType[Int, StepOps]
import scala.language.implicitConversions
object Test extends App {
testShapeless()
TestSupertagged.testSupertagged()
def testShapeless(){
import shapeless.newtype
@rudogma
rudogma / 0-prepare.md
Last active June 26, 2017 19:01
Scala native tagged types + superquants 40x slower then jvm ((
clone https://github.com/milessabin/shapeless.git
cd shapeless
sbt
-- in sbt:
++2.11.11
coreNative/publishM2
exit

clone https://github.com/Rudogma/scala-superquants.git
@rudogma
rudogma / OverTagged0_F.scala
Last active June 24, 2017 12:09
OverTagged: typelevel inheritance(like extend, but with tags on typelevel)
import org.scalatest.{FlatSpec, Matchers}
import shapeless.test.illTyped
import TestOverTagged2._
import supertagged.{OverTagged, Tag, Tagged, TaggedType, TaggedTypeF}
import scala.language.higherKinds
class TestOverTagged2 extends FlatSpec with Matchers {
@rudogma
rudogma / MultiDimensional.scala
Last active June 16, 2017 12:14
Using tagged types as alternative (with no runtime overhead) to Compile time dimensional analysis at http://typelevel.org/blog/2017/06/13/libra.html
import supertagged._
/*** ONE TIME PREDEF **/
trait Opp {
type Operation
type Divide <: Operation
type Multiply <: Operation
}
@rudogma
rudogma / FutureFlattenPlusShapelessNatCounter.scala
Last active June 13, 2017 20:39
Count nested implicits level using shapeless.Nat (flatten future as example)
import shapeless.ops.nat.ToInt
import shapeless.{Nat, Succ}
import scala.concurrent.Promise
import scala.util.{Failure, Success}
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits._
@rudogma
rudogma / 0.Test.scala
Last active May 30, 2017 19:33
Danger! High voltage!
import scala.language.dynamics
object Test extends App {
implicit class MyVal[T](val value:T) extends AnyVal
class Test1 extends Dynamic {
def selectDynamic(field:String):String = "Hello"
}