Skip to content

Instantly share code, notes, and snippets.

@dorsev
dorsev / Scala-why-we-love-exhaustive-check.md
Created December 1, 2020 08:13
Scala-why-we-love-exhaustive-check

Scala gives us the sealed keyword, which allows the compiler to check at compile time that all cases of a type have been handled with So the compiler checks in compile-time - yes. - compile-time -that you handled all the cases.

Why is this insanely useful(IMO - the biggest advantages of scala over a lot of languages): let's take an example: When you write a calculator

Sealed trait Expression {
 case class Add(left:Int,right:Int) extends Expression
@dorsev
dorsev / WordCountStreams.scala
Last active November 16, 2020 08:51
ZStream word count example
package wordCount
import java.io._
import zio._
import zio.console._
import zio.stream.{ZStream, ZTransducer}
object wordCount extends zio.App {
def run(args: List[String]) =
@dorsev
dorsev / tsconfig.json
Created August 15, 2020 10:20
Your first tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"allowJs": true,
"checkJs": false,
"outDir": "dist",
"rootDir": ".",
"strict": false,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
@dorsev
dorsev / sentiment.analysis.metrics.list.txt
Created March 4, 2020 20:16
full list of metrics used in our sentiment analysis software
A complete list of the metrics and names I added were:
latency metrics list
processing_duration_ms - histogram - which measures processing latencies.
deserialize_duration_ms - histogram - which measures how long it takes to deserialize a request
serialize_duration_ms - histogram - which measures how long it takes to serialize an event
store_duration_ms - histogram - which measures how long it takes to store(index/save/persist) a state change.
with all of these, I can now define a total_processing_duration_ms which will be deserialize_duration_ms + serialize_duration_ms + store_duration_ms + processing_duration_ms
Applicative usage metrics
incoming_requests_count - counter - which will indicate how many requests did we process. Using this metric we can define throughput!
@dorsev
dorsev / sentiment.analysis.service.ts
Last active March 6, 2020 11:55
sentiment analysis example - with metrics
import SDC = require("statsd-client");
let sdc = new SDC({ host: 'localhost' });
let senService: SentimentAnalysisService; //...
while (true) {
let tweetInformation = kafkaConsumer.consume()
sdc.increment('incoming_requests_count')
let deserializedTweet: { msg: string } = deSerialize(tweetInformation)
sdc.histogram('request_size_chars', deserializedTweet.msg.length);
let sentimentResult = senService.calculateSentiment(deserializedTweet.msg)
if (sentimentResult !== undefined) {
@dorsev
dorsev / sentiment.analysis.service.ts
Last active March 28, 2020 06:42
Sentiment Analysis example - without metrics
let senService: SentimentAnalysisService = new SentimentAnalysisService();
while (true) {
let tweetInformation = kafkaConsumer.consume()
let deserializedTweet: { msg: string } = deSerialize(tweetInformation)
let sentimentResult = senService.calculateSentiment(deserializedTweet.msg)
let seriarliedSentimentResult = serialize(sentimentResult)
sentimentStore.store(sentimentResult);
kafkaProducer.produce(seriarliedSentimentResult, 'sentiment_topic', 0);
}
@dorsev
dorsev / euler-solution-1.js
Created January 3, 2020 19:55
project-euler-solutions
function multiplesOf3and5(number) {
return [...Array(number).keys()].filter((x) => {
if(x % 3 == 0 || x % 5 == 0){
return x;
} else return 0;
}).reduce((agg,elem) => agg+elem, 0);
}
curl -X PUT "localhost:9200/my_index_2?pretty" -H 'Content-Type: application/json' -d'
{
"mappings": {
"_doc": {
"properties": {
"tags": {
"type": "object",
"properties": {
"keyToValue": {
"type": "keyword"
curl -X PUT "localhost:9200/my_index?pretty" -H 'Content-Type: application/json' -d'
{
"mappings": {
"_doc": {
"properties": {
"tags": {
"type": "nested"
}
}
}
@dorsev
dorsev / DynamicFieldQuery.sh
Last active December 24, 2019 23:11
query on dynamic template field
curl -X GET "localhost:9200/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query": {
"match" : {
"actions.tags.name" : {
"query" : "John"
}
}
}