Skip to content

Instantly share code, notes, and snippets.

@davideicardi
davideicardi / Dockerfile
Created Nov 24, 2021
Dockerfile template for node following best practices
View Dockerfile
# References:
# https://nodejs.org/en/docs/guides/nodejs-docker-webapp/
# https://github.com/nodejs/docker-node/blob/main/docs/BestPractices.md
# https://adambrodziak.pl/dockerfile-good-practices-for-node-and-npm
FROM node:16.13-alpine3.12 AS builder
WORKDIR /usr/src/app
View gist:ba15ebc5d784bd670723c16627eddcc9
#!/bin/bash
# set -e = exit in case of errors
# set -u = no undefined variable
# set -o pipefail = prevent pipeline errors
# more info: https://gist.github.com/usametov/a134115a0fa1157b45ea5d432510d2f6
set -euo pipefail
# TODO Add your script
@davideicardi
davideicardi / FutureUtils.scala
Last active Jan 29, 2021
Scala Future utilities to process elements asynchronous one after another
View FutureUtils.scala
import scala.concurrent.{ExecutionContext, Future}
object FutureUtils {
/**
* Process elements asynchronous one after another.
* Equivalent to `Future.sequence(elements.map(transform))`
* but doing the processing sequentially instead of in parallel
*/
def mapAsyncSequentially[TInput, TResult](elements: Iterable[TInput])
(mapFunction: TInput => Future[TResult])
@davideicardi
davideicardi / SimpleTopology.scala
Last active Sep 30, 2020
Simple Kafka Streams Testing
View SimpleTopology.scala
import java.util.Properties
import org.apache.kafka.streams.scala.ImplicitConversions._
import org.apache.kafka.streams.scala._
import org.apache.kafka.streams.scala.kstream._
import org.apache.kafka.streams.{StreamsConfig, Topology}
import Serdes._
class SimpleTopology(
val bootstrapServers: String,
@davideicardi
davideicardi / README.md
Created Sep 12, 2020
Publish Maven library to Github packages with SBT and github actions
View README.md

Publish

Add the following configuration to your build.sbt:

  // publish to github packages settings
  publishTo := Some("GitHub <GITHUB_OWNER> Apache Maven Packages" at "https://maven.pkg.github.com/<GITHUB_OWNER>/<GITHUB_PROJECT>"),
  publishMavenStyle := true,
  credentials += Credentials(
    "GitHub Package Registry",
View docker-compose.yml
# https://github.com/wurstmeister/kafka-docker
# https://medium.com/big-data-engineering/hello-kafka-world-the-complete-guide-to-kafka-with-docker-and-python-f788e2588cfc
version: '3'
services:
zookeeper:
image: wurstmeister/zookeeper:3.4.6
ports:
- "2181:2181"
@davideicardi
davideicardi / AutoVersion.scala
Last active Aug 31, 2020
Calculate version for an SBT project
View AutoVersion.scala
/*
Calculate project's version using GIT tags and commits.
Main idea is to avoid having a version written in the source code but instead link it to the GIT repository.
It is similar to sbt-git plugin but increment the PATCH part when there are additional commits.
The version is calculated using the last tag and the last commit (using `git describe` output).
If there is at least one commit after the last tag the PATCH part is incremented by 1
and `-SNAPSHOT` is added as a suffix.
Otherwise the tag is used as is.
@davideicardi
davideicardi / sw-audio-in
Last active Feb 2, 2020
Switch audio scripts bash script for Ubuntu
View sw-audio-in
#!/bin/bash
set -e
NEW_SOURCE=1
DEFAULT_SOURCE=`pacmd list-sources | grep '* index' | cut -f5 -d' '`
if [ $DEFAULT_SOURCE -eq 1 ]
then
NEW_SOURCE=0
fi
@davideicardi
davideicardi / README.md
Last active Feb 7, 2021
Package a Python Lambda for AWS
View README.md

Package a Python Lambda for AWS

Python virtual env

Create Python virtual env

python3 -m venv v-env

Activate

@davideicardi
davideicardi / README.md
Created Aug 6, 2019
Read kinesis data from aws cli
View README.md

aws kinesis get-shard-iterator --stream-name YOUR_STREAM_NAME --shard-id 0 --shard-iterator-type TRIM_HORIZON

aws kinesis get-records --shard-iterator YOUR_SHARD_ITERATOR