Skip to content

Instantly share code, notes, and snippets.

kenji yoshida xuwei-k

Block or report user

Report or block xuwei-k

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@xuwei-k
xuwei-k / RuntimeUtils.scala
Created Oct 14, 2019 — forked from jvican/RuntimeUtils.scala
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.
View RuntimeUtils.scala
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);
@xuwei-k
xuwei-k / sonatypeBundleDirectory.md
Last active Oct 14, 2019
sbt-sonatypeのsonatypeBundleDirectoryを微妙に修正するべき?という話
View sonatypeBundleDirectory.md

前提や問題点の説明

  • sbt-sonatypeのversion 3.8時点の話
  • 最近のsbt-sonatypeは、一旦全部ローカルの特定のディレクトリにjarやpomをpublishして、それをまとめてuploadするという、bundle releaseという方式が導入された
  • sonatypeBundleDirectoryはその際のディレクトリのためのSetting Key
  • "まとめてupload" なので、もちろん基本的には、一つのディレクトリに全部一旦publishして、1回だけuploadするのが通常の使い方として想定されているはず
  • (なぜか同名の未使用のTaskKeyが定義されているが?)sonatypeBundleReleaseはcommandとして定義されている https://github.com/xerial/sbt-sonatype/blob/3.8/src/main/scala/xerial/sbt/Sonatype.scala#L144-L145
  • SettingKeyやTaskKeyは、sub project毎に違う値や動作を持てる。一方Commandは、(単純に言えば)指定されたものを順次sbtのconsoleから実行するイメージに近い
  • versionもSettingKey
  • つまり、sonatypeBundleDirectoryの値は、versionを使って定義されているが、sub project毎にversionが違えば、sonatypeBundleDirectoryの値も異なることになるはず
View Main.scala
package example
case class IO[A](private val run: () => A) {
def unsafeRun(): A = run()
def map[B](f: A => B): IO[B] = IO(() => f(run()))
def flatMap[B](f: A => IO[B]): IO[B] = IO(() => f(run()).run())
}
case class Ref[A](private var value: A) {
def get: IO[A] = IO(() => value)
View CatsRefUnsafeExample.scala
package example
import cats.effect.concurrent.Ref
import cats.effect._
import cats.syntax.traverse._
import cats.instances.list._
// https://github.com/typelevel/cats-effect/blob/v2.0.0/core/shared/src/main/scala/cats/effect/concurrent/Ref.scala#L208
object CatsRefUnsafeExample extends IOApp {
override def run(args: List[String]) = {
View runAll.sbt
val runAll = taskKey[Unit]("run all main")
runAllIn(Compile)
def runAllIn(config: Configuration) = {
runAll in config := {
val r = (runner in run).value
val classpath = (fullClasspath in config).value
val log = streams.value.log
(discoveredMainClasses in config).value.foreach(c =>
@xuwei-k
xuwei-k / scala_2.13.1_binary_incompatibilities.txt
Created Sep 18, 2019
Scala 2.13.0 => 2.13.1 binary incompatibilities
View scala_2.13.1_binary_incompatibilities.txt
* abstract method result(scala.concurrent.duration.Duration,scala.concurrent.CanAwait)java.lang.Object in interface scala.concurrent.Awaitable has a different signature in current version, where it is (Lscala/concurrent/duration/Duration;Lscala/concurrent/CanAwait;)TT;^Ljava/util/concurrent/TimeoutException;^Ljava/lang/InterruptedException; rather than (Lscala/concurrent/duration/Duration;Lscala/concurrent/CanAwait;)TT;^Ljava/lang/Exception;
filter with: ProblemFilters.exclude[IncompatibleSignatureProblem]("scala.concurrent.Awaitable.result")
* static method result(scala.concurrent.Awaitable,scala.concurrent.duration.Duration)java.lang.Object in class scala.concurrent.Await has a different signature in current version, where it is <T:Ljava/lang/Object;>(Lscala/concurrent/Awaitable<TT;>;Lscala/concurrent/duration/Duration;)TT;^Ljava/util/concurrent/TimeoutException;^Ljava/lang/InterruptedException; rather than <T:Ljava/lang/Object;>(Lscala/concurrent/Awaitable<TT;>;Lscala/concurrent/duration/Duration;)TT;
View A.javap
Classfile /Users/kenji/structural-subtype-javap/A.class
Last modified Aug 12, 2019; size 2453 bytes
MD5 checksum dc2e1948b339005c82b1948b25e9356f
Compiled from "A.scala"
public class A
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Utf8 A
@xuwei-k
xuwei-k / A.javap
Created Aug 11, 2019
Boolean + String
View A.javap
Classfile /Users/kenji/boolean-plus-string/A.class
Last modified Aug 11, 2019; size 1859 bytes
MD5 checksum 45a441997ea15f8a84c80f23f1f0bfe1
Compiled from "A.scala"
public class A
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
Constant pool:
#1 = Utf8 A
View replace-symbol-literal-global-build.sbt
// https://github.com/xuwei-k/replace-symbol-literals
{
val Scalafix = "Scalafix"
val removeCommand = "removeTemporaryScalafix"
def tempPluginDotSbtFile (base: File) =
base / "project" / ("temporaryScalafix.sbt")
Seq(
@xuwei-k
xuwei-k / InjectorOps.scala
Last active Jul 29, 2019
guice TypeLiteral macro in Scala
View InjectorOps.scala
package scala_guice_macro
import com.google.inject.Injector
import scala.reflect.macros.blackbox
import scala.language.experimental.macros
object InjectorOps {
implicit def toInjectorOps(i: Injector): InjectorOps = new InjectorOps(i)
}
You can’t perform that action at this time.