Skip to content

Instantly share code, notes, and snippets.

@mirkoprescha
mirkoprescha / python_mock_batch_boto3.py
Created December 10, 2019 07:50
Python: Patch inner function call to S3 using unittest.mock
######################################
'''
Patch inner function call to S3
'''
######################################
######################################
### file python/test/my_class.py
######################################
@mirkoprescha
mirkoprescha / kafka-scala-consumer.scala
Created September 19, 2019 18:31
simple kafka consumer in scala
import java.nio.charset.StandardCharsets
import java.util.Properties
import org.apache.kafka.common.TopicPartition
import org.apache.kafka.common.serialization.{Serdes, StringDeserializer}
import org.apache.kafka.common.serialization.Serdes.StringSerde
import org.apache.kafka.streams.scala.StreamsBuilder
import scala.collection.immutable
YAML - Anchors, References, Extend
YAML is pretty cool for config files. I don't think it should be used 'on the wire' - I suppose you could, but it's more for people than machines.
Most of YAML can be converted into JSON, and I would say most applications use it that way.
Basics
---
foo: bar
baz:
- "thing1"
@mirkoprescha
mirkoprescha / bash_script.sh
Created January 11, 2019 08:13
call bash script independent of caller directory
#!/usr/bin/env bash
DIRNAME="$( dirname "${BASH_SOURCE[0]}" )"
$DIRNAME/my-subscript.sh
@mirkoprescha
mirkoprescha / sbt-scala-logging
Created January 9, 2019 13:06
logging dependencies
// logging
libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.9.0"
libraryDependencies += "org.slf4j" % "slf4j-log4j12" % "1.7.25"
@mirkoprescha
mirkoprescha / k8s.deployment.service.yaml
Created December 3, 2018 10:30
k8s deployment-service template
---
apiVersion: v1
kind: Service
metadata:
labels:
app: ${MY_APPLICATION}
name: ${MY_APPLICATION}
name: ${MY_APPLICATION}
spec:
type: ${MY_APPLICATION_SERVICE_PORT_TYPE}
@mirkoprescha
mirkoprescha / schema_registry_register_local
Created July 11, 2018 06:31
register schema of avro generated classes
// USED FOR LOCAL TESTING USING CONFLUENT PLATFORM
val sr = new CachedSchemaRegistryClient ("http://localhost:8081",100)
sr.register("getFullCustParaSession_1-key",webtrekkSid.SCHEMA$)
sr.register("getFullCustParaSession_1-value",getFullCustParaSession_1.SCHEMA$)
sr.register("getFullForms-key",webtrekkSid.SCHEMA$)
sr.register("getFullForms-value",getFullForms.SCHEMA$)
val subs = sr.getAllSubjects
subs.forEach(println(_))
@mirkoprescha
mirkoprescha / Guide-to-JMX-Monitoring.md
Created May 15, 2018 11:45
Guide to JMX Monitoring (datadog)

Guide to JMX Monitoring

Retrieve JMX metrics without GUI

Instead of jconsole you can use jmxterm to discover and watch metrics. This is useful if you don't have X11 or need a more lightweight solution.

wget https://github.com/jiaqi/jmxterm/releases/download/v1.0.0/jmxterm-1.0.0-uber.jar
@mirkoprescha
mirkoprescha / aws-sdk-with-dynamic-credentials.scala
Created February 14, 2018 09:11
aws-sdk using aws profile with dynamic credentials
import com.amazonaws.auth.profile.ProfileCredentialsProvider
import com.amazonaws.regions.Regions
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder
object myDynamoDBTest extends App {
val pcp: ProfileCredentialsProvider = new ProfileCredentialsProvider("myProfileName")
val client = AmazonDynamoDBClientBuilder.standard().withCredentials(pcp).withRegion(Regions.EU_CENTRAL_1).build()
val table_names = client.listTables().getTableNames

Place src/main/resources/application.conf with some props:

kafka-consumer-config {
  bootstrap-servers = ["localhost:9092"]
  group-id = "kafka-consumer-example"
  topic = "my-example-topic"
  key-deserializer = "org.apache.kafka.common.serialization.StringDeserializer"