Skip to content

Instantly share code, notes, and snippets.

View NicolaeNMV's full-sized avatar

Nicu Namolovan NicolaeNMV

View GitHub Profile
@NicolaeNMV
NicolaeNMV / akka-intellij-worksheet-work-arround.md
Last active February 17, 2021 15:35
How to run akka actors in Intelij Worksheet

Missing resource

Scala code run from Intellij Worksheet doesn't seem to be able to find the akka actor resources.

The error is:

com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka'

There is an opened ticket on Intellij bugtracker https://youtrack.jetbrains.com/issue/SCL-9229 with a work arround

@NicolaeNMV
NicolaeNMV / fix_bsonobjectid_implicit.scala
Created January 10, 2015 14:16
Solve ReactiveMongo playframework scala "No implicit format for reactivemongo.bson.BSONObjectID available."
import play.api.libs.json.{Json, Format}
// If you imported
import play.modules.reactivemongo.json.BSONFormats.BSONObjectIDFormat
// And still getting No implicit format for reactivemongo.bson.BSONObjectID available. error
// Check that your JSON formatter is typed. Change
implicit val mongoFormat = Json.format[Category]
// to
implicit val mongoFormat: Format[Category] = Json.format[Category]
@NicolaeNMV
NicolaeNMV / base64_binary_to_ascii_enc_dec.scala
Last active September 15, 2018 16:53
Encode/Decode Ascii->Binary->Base64 in Scala
// Multistep encoding of ascii to binary->base64
// As the binary will be presented as blocks of 0,1 separated by space.
// The base64 result will contain patterns such as MTA, MCA, IDE.
val message = "Hello World !"
def encode(message: String): String =
java.util.Base64.getEncoder().encodeToString( message.map(_.toBinaryString).mkString(" ").map(_.toByte).toArray )
def decode(base64: String): String =
@NicolaeNMV
NicolaeNMV / StreamBroadcastSampleAmm.scala
Created February 6, 2017 07:50
Playing with reactive streams and ammonite
#!/usr/bin/env amm
import $ivy.`com.typesafe.akka::akka-stream:2.4.16`
import java.nio.file.Paths
import akka.NotUsed
import akka.stream._
import akka.stream.scaladsl._
import akka.actor.ActorSystem
import akka.util.ByteString
@NicolaeNMV
NicolaeNMV / start_notebook_with_spark.sh
Created January 7, 2017 08:51
Start jupyter notebook with spark
#!/bin/sh
export PYSPARK_DRIVER_PYTHON="/usr/local/bin/jupyter"
export PYSPARK_DRIVER_PYTHON_OPTS="notebook --NotebookApp.open_browser=False --NotebookApp.ip='*' --NotebookApp.port=8880"
export PYSPARK_PYTHON="/usr/bin/python"
pyspark
@NicolaeNMV
NicolaeNMV / gist:6909e217df58a85791a5
Last active February 14, 2016 11:17
Slick mysql playframework 2.4 configure for emoji
The default utf8 character set doesn't support emoji characters, you'll see `[SQLException: Incorrect string value: '\xF0\x9F\x98\x8A P...' for ` exception when trying to insert data.
You'll need utf8mb4 character set to be able to sotre emoji characters.
1. You'll need to create all the tables with CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci option
2. After initializing the conneciton, you will need to send SET NAMES utf8mb4,
you can do that with the hikari connectionInitSql option, a SQL statement that will be executed after the connetion was initialized.
slick.dbs.default.db.connectionInitSql="set names utf8mb4"
@NicolaeNMV
NicolaeNMV / sbt_debug_run.sh
Created January 21, 2014 14:49
How to launch a play2 application in debug mode with sbt
# Declare a env. variable with JPDA params
export SBT_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=9999 "
sbt run
# You should see: "Listening for transport dt_socket at address: 9999"
# From your IDE, configure Remote Debugging. As described here http://www.playframework.com/documentation/2.2.x/IDE
@NicolaeNMV
NicolaeNMV / pgp_public_key
Created November 26, 2013 13:03
My public PGP key
Now you can verify thats really me who sent something.
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBFKUmVwBEAD0R5jfFQBQ/bQBHjAR9l5db4S76sFjxJyelPzMB/Q0GNQYyhVs
Ren/PaYR8g3xOVC60bv2swH3PWZfaAhenlnvVxXmymUnWeuB+TULoxY74xSuEpFa
jKdC2Z+hgXLKBMJZNtOWnnLWuCdpCNr+JhA8vL42fzfK9pXMpxi+UzrS2VGe8/7t
+e+6s2G/FuBLBq1PGAzswsouziZQ+XI4BLCZzz4K0TV5pZQ6fc6l2yMCeiVaOqF8
TOAO3+Zx4qvSCeO1cJcJ8Jh+mCCkhe1aUHMjiiVGew0aBJpxov339zOy325VdZ7K
Y67ozytQxR7qly1yI7SakuQM/SYhviL9KnveHzYyJZTT/d6Glc4pZFEbVKo/fHEj
@NicolaeNMV
NicolaeNMV / gist:d3d9d9958b7769e8d48a
Created May 29, 2015 12:26
reactive-stream FlowMaterializer

If you were playing with reactive-stream, and you got this error

scala> val sum = source.runWith(sink)
<console>:14: error: could not find implicit value for parameter materializer: akka.stream.FlowMaterializer

You need an implicit FlowMaterializer

def runWith[Mat2](sink: Graph[SinkShape[Out], Mat2])(implicit materializer: FlowMaterializer): Mat2

@NicolaeNMV
NicolaeNMV / filterusableipv4addreses.sh
Created December 23, 2011 16:32
filterusableipv4addreses.sh
#to generate:
#curl http://www.iana.org/assignments/ipv4-address-space/ipv4-address-space.txt | grep "/8" | egrep "LEGACY|ALLOCATED" | sed -e "s/^[ \t]*//g" | cut -f 1 -d " " | awk '{split($0,a,"/");print a[1]".0.0.0/"a[2]}