Skip to content

Instantly share code, notes, and snippets.

@davideicardi
davideicardi / print-iso8601-date.sh
Created May 25, 2022
How to print current date as UTC ISO 8601 format
View print-iso8601-date.sh
date --utc --iso-8601=seconds
@davideicardi
davideicardi / remove-git-branches.sh
Last active May 4, 2022
Remove all GIT branches that match a specific name using bash
View remove-git-branches.sh
# Remove all GIT branches starting with `fix/`, just locally
git branch | grep fix/ | xargs -I '{}' git branch -d '{}'
@davideicardi
davideicardi / aws-console
Last active May 18, 2022 — forked from ottokruse/aws-console
Python script to launch the AWS console in your webbrowser, using a presigned URL generated from your AWS CLI credentials
View aws-console
#!/usr/bin/env python3
"""
Based on: https://gist.github.com/ottokruse/1c0f79d51cdaf82a3885f9b532df1ce5
Usage:
- Save this script somewhere on your path (e.g. `vi /usr/local/bin/aws-console && chmod +x /usr/local/bin/aws-console`)
- Install dependencies: pip install boto3
- Make AWS credentials available in one of the usual places where boto3 can find them (~/.aws/credentials, env var, etc.)
- Excute the script: `AWS_PROFILE=your-profile aws-console`
- :tada: Your browser opens and you are signed in into the AWS console
@davideicardi
davideicardi / azure-pipelines.yaml
Created Dec 21, 2021
Calculate version inside an Azure DevOps pipeline using counter function
View azure-pipelines.yaml
# Calculate version that will be incremented for each build whenever Major or Minor change, and different for each branch.
# Solution based on https://k2vacademy.com/2019/04/03/hidden-gems-in-azure-pipelines-creating-your-own-rev-variable-using-counter-expression-in-azure-pipelines/
# This could be useful if gitversion cannot be used.
# Otherwise the best solution is to use instead the default gitversion task: https://github.com/GitTools/actions/blob/main/docs/examples/azure/gitversion/execute/usage-examples.md
# ....
variables:
# Versioning is handled using a format like major.minor.patch{-snapshot}
# Major and Minor are fixed, patch is calculated using a counter (it will reset to 0 every time other values change).
@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"