Skip to content

Instantly share code, notes, and snippets.

View satorg's full-sized avatar

Sergey Torgashov satorg

View GitHub Profile
@satorg
satorg / BugObservableZip3App.scala
Created February 14, 2018 18:48
Monix Observable.zip3 bug
/*
* Java 1.8.0_162
* Scala 2.12.4
* SBT 1.1.0
* Monix 3.0.0-M3
*/
package satorg.monix_gs
import monix.execution.Scheduler.Implicits.global
import monix.reactive._
@satorg
satorg / memoizeExpiring.scala
Created March 6, 2018 19:15
memoizeExpiring
import monix.eval._
import monix.execution.atomic.Atomic
def memoizeExpiring[A](sourceTask: Task[A], interval: FiniteDuration): Task[A] = {
class State {
val memoizedTask: Task[A] = sourceTask.memoize
val deadline: Deadline = interval.fromNow
}
@satorg
satorg / scala-compile-server-options.md
Last active March 20, 2022 09:05
HOWTO FIX: "Warning:scalac: Cannot connect to compile server at localhost/127.0.0.1:3200 Trying to compile without it"

Applicable for:

  • IntelliJ IDEA CE 2019.1 (2018.* – ?)
  • macOS Mojave
  • may also work for other IDEA/macOS versions

Steps to fix:

  1. Go to directory ~/Library/Preferences/IdeaIC${IDEA_VERSION}/
    • for IntelliJ IDEA CE 2019.1: ~/Library/Preferences/IdeaIC2019.1/.
  2. There're two files in this directory:
  • ./settingsRepository/repository/scala.xml;
@satorg
satorg / Scala_2_12_7_regression.scala
Created March 8, 2019 21:43
Demonstrates a regression bug introduced by Scala 2.12.7 update
import org.scalatest.Matchers._
object SampleApp extends scala.App {
implicit class IterableOps[A](private val self: Iterable[A]) extends AnyVal {
def countUniqueItems: Map[A, Int] = ??? // implementation doesn't matter
}
// Fails to compile on Scala 2.12.7 and 2.12.8 with the following error:
// [error] <CUT>/scalatest-issue/src/main/scala/SampleApp.scala:13:24: could not find implicit value for parameter emptiness: org.scalatest.enablers.Emptiness[Map[A,Int]]
@satorg
satorg / .scalafmt.conf
Created July 7, 2020 04:37
IntelliJ IDEA: SBT download plugin sources
version = 2.6.2
style = default
@satorg
satorg / aes-encrypt-decrypt-message.scala
Last active October 2, 2020 04:01
Simple message encryption/decryption with AES
val iv = new IvParameterSpec(Base64.getDecoder.decode("V4kfws5dKNgK0ORjb8jCtQ=="))
def mkKeySpec(key: String, load: Int) = {
val digest = MessageDigest.getInstance("SHA-256")
var bytes = key.getBytes(UTF_8)
for (_ <- 0 until load) {
bytes = digest.digest(bytes)
}
new SecretKeySpec(bytes, "AES")
}
@satorg
satorg / SPBCryptor.scala
Last active September 22, 2020 06:45
Simple Password Based Encryptor/Decryptor
import java.nio.ByteBuffer
import java.security.{Key, SecureRandom}
import javax.crypto.spec.{IvParameterSpec, PBEKeySpec, SecretKeySpec}
import javax.crypto.{Cipher, SecretKeyFactory}
import scala.util.chaining._
class SPBCryptor(iterationCount: Int = SPBCryptor.DefaultIterationCount) {
@satorg
satorg / macos-quarantine-remove
Created October 31, 2020 03:51
Remove some app from MacOS quarantine
xattr -d com.apple.quarantine <path-to-the-app>
@satorg
satorg / list-jvm-procs.sh
Created June 4, 2021 18:23
List JVM processes with passed parameters
jps -lvm
@satorg
satorg / realpath.py
Last active June 14, 2021 18:49
Portable realpath script implementation in Python3
#!/usr/bin/env python3
from argparse import *
import pathlib
import os
parser = ArgumentParser(
description='follow a symlink recursively.'
)