Skip to content

Instantly share code, notes, and snippets.

View fanf's full-sized avatar

François Armand fanf

View GitHub Profile
@fanf
fanf / TestDefaultRuntime.scala
Last active March 10, 2020 21:32
Deadlock in ZIO with `Runtime.default` runtime
/*
Dependencies:
- scala 2.13.1
- zio 1.0.0-RC18-1+44-24f507c2+20200310-2150-SNAPSHOT (local build on master on 2020-03-10)
- with openjdk 11.0.4+11
*/
package some.pkg
import zio.Runtime
@fanf
fanf / TestRuntime.scala
Created March 10, 2020 12:32
Deadlock with ZIO runtime / init in object
object TestRuntime {
object internal {
val platform : _root_.zio.internal.Platform = _root_.zio.internal.Platform.makeDefault()
// a local runtime just to build first zlayer
private val r = Runtime((), platform)
// non memomized env
val env = ZEnv.live
val runtime = Runtime.unsafeFromLayer(env, platform)
@fanf
fanf / key.md
Last active January 9, 2020 17:28
Twitter (un)official Consumer Key

Twitter Official Consumer Key

Twitter for Android - REVOKED SINCE DECEMBER 2019

type:            PIN
Consumer key:    3nVuSoBZnx6U4vzUxf5w
Consumer secret: Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys

Twitter for iPhone

type:            PIN

Consumer key: IQKbtAYlXLripLGPWd0HUA

package com.normation
import scala.concurrent.Future
object CheckMemoryReleaseFlatMap {
def getFreeMem = (Runtime.getRuntime().freeMemory() / (1024*1024)).toString + " MB"
def doGC = {
System.gc()
System.runFinalization()
2019-11-30 17:28:06
Full thread dump OpenJDK 64-Bit Server VM (11.0.4+11 mixed mode):
Threads class SMR info:
_java_thread_list=0x00007f2104006610, length=92, elements={
0x00007f21bc099800, 0x00007f21bc618000, 0x00007f21bc629000, 0x00007f21bc63b800,
0x00007f21bc63d000, 0x00007f21bc63f000, 0x00007f21bc641000, 0x00007f21bc77e800,
0x00007f21bcc56000, 0x00007f21bcc5a800, 0x00007f21bcc5d800, 0x00007f21bccad800,
0x00007f2160001800, 0x00007f21bccb6800, 0x00007f2144476800, 0x00007f2140066000,
@fanf
fanf / threadlock.tdump
Created November 30, 2019 15:33
ZIO threadlock
2019-11-30 16:28:59
Full thread dump OpenJDK 64-Bit Server VM (11.0.4+11 mixed mode):
Threads class SMR info:
_java_thread_list=0x00007fe294127730, length=113, elements={
0x00007fe370098800, 0x00007fe370617000, 0x00007fe370628000, 0x00007fe37063a800,
0x00007fe37063c000, 0x00007fe37063e800, 0x00007fe370640800, 0x00007fe37075d800,
0x00007fe370c06000, 0x00007fe370c32000, 0x00007fe370c33800, 0x00007fe304456000,
0x00007fe300062800, 0x00007fe300064000, 0x00007fe300066000, 0x00007fe370c93800,
@fanf
fanf / selectAndExecCallback.scala
Last active September 14, 2019 16:55
Select a callback given a value, and exec an associated callback
class Callbacks[A, E, CE] {
// callbacks are all returning Units with a generic callback error `CE` type.
type READER = IO[E, (Int, IO[CE, Unit])]
def reader1(): READER = ???
def reader2(): READER = ???
def reader3(): READER = ???
// manager function call readers, does its business decision algo and return according callback
def manager(readers: List[READER]): READER = {
// default callback (if no readers // no reader with positive value) does nothing
@fanf
fanf / CountSetMemory.scala
Last active September 5, 2019 15:53
Scala keySet keep reference on self, forbig GC
package test
import net.sourceforge.sizeof.SizeOf
object CountSetMemory {
def bigArray = new Array(1024*1024)
def main(args: Array[String]): Unit = {
val map = Map(1 -> bigArray, 2 -> bigArray, 3 -> bigArray)
val keys1 = map.keySet
val keys2 = map.keySet.toSeq.toSet
import zio._
import zio.syntax._
// ZIO version 2.12-1.0.0-RC9.4
object Deadlock {
val runtime = new DefaultRuntime {}
trait Logger {
@fanf
fanf / setLogbackAppender.scala
Created July 17, 2019 21:17
Programatically set ByteArrayOutputStream appender for logback logger in scala
// this was driving me crazy, so here we are, for everyone.
// inspiration from https://stackoverflow.com/questions/19058722/creating-an-outputstreamappender-for-logback
import ch.qos.logback.classic.Logger
import ch.qos.logback.classic.LoggerContext
import ch.qos.logback.classic.encoder.PatternLayoutEncoder
import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.OutputStreamAppender
import org.slf4j.LoggerFactory