Skip to content

Instantly share code, notes, and snippets.

View cspinetta's full-sized avatar
👨‍💻
I may be slow to respond.

Cristian Spinetta cspinetta

👨‍💻
I may be slow to respond.
View GitHub Profile
@cspinetta
cspinetta / main.go
Created April 19, 2021 20:05
Simulate a large payload on the fly with an io.Reader
package main
import (
"fmt"
"io"
)
func main() {
r := NewDataGenerator(1000)
@cspinetta
cspinetta / synchronization-implementation-in-jvm.md
Last active February 24, 2022 15:45
Synchronization in Java

Object locking implementation in the Java HotSpot VM

The most synchronization idiom in Java is using the synchronized keyword.

The JVM supports synchronization of both methods and sequences of instructions within a method using a single synchronization construct - synchronized - which is built around an internal entity known as the intrinsic lock or monitor lock (The API specification often refers to this entity simply as a "monitor"). Intrinsic locks play a role in both aspects of synchronization: enforcing exclusive access to an object's state and establishing happens-before relationships to ensure a correct visibility amoung threads.

At bytecode level, the JVM supplies the monitorenter and monitorexit instructions to support such constructs.

At runtime level, in the Java HotSpot VM, every object has a built-in monitor (the so called intrinsic lock or monitor lock) that can be acquired by any thread.

@cspinetta
cspinetta / docker-compose.yml
Created May 21, 2020 12:26
Promtail example extracting data from json log
version: "3.6"
services:
promtail:
image: grafana/promtail:1.4.0
container_name: promtail
command: [ "-config.file=/etc/promtail/local-config.yaml" ]
volumes:
- './promtail.yml:/etc/promtail/local-config.yaml:ro'
- '__path_to_logs_directory__:/app/log:ro'
#!/usr/bin/env bash
cat /proc/net/tcp* | awk '
{
TOTAL += $7;
COUNT++;
}
END {
printf "rate_retr %.3f\n", TOTAL/COUNT
}
@cspinetta
cspinetta / docker-compose-workshop-troubleshooting.yml
Last active January 17, 2020 13:27
Docker compose for workshop "system tools for dev"
version: '3.4'
services:
external-api:
image: cspinetta/workshop-external-api:0.1
network_mode: "host"
# ports:
# - "9290:9290"
internal-api:
image: cspinetta/workshop-internal-api:0.1
network_mode: "host"
@cspinetta
cspinetta / jthreads_stats.py
Last active May 18, 2020 19:24
Java Thread Stats based on pidstat + jstack + /proc/.../schedstat
#!/usr/bin/env python3
import os
import re
import sys
import subprocess
import curses
import traceback
import argparse
from curses import wrapper
@cspinetta
cspinetta / SnakeCaseSerializer.scala
Created November 20, 2018 15:15
Jackson ObjectMapper
package base.serializer
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility
import com.fasterxml.jackson.annotation.{JsonInclude, PropertyAccessor}
import com.fasterxml.jackson.databind._
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.module.scala.experimental.ScalaObjectMapper
import play.api.libs.json.{JsValue, Json}
@cspinetta
cspinetta / Exercises for learning Scala
Last active January 25, 2019 15:48
Exercises for learning Scala
* Implementar `MyOptional`
* Implementar `StudentsAnalyzer`
@cspinetta
cspinetta / installation-of-stuffs.md
Created November 15, 2018 01:19
Instalaciones para Workshop de Scala

Instalar IntellijIDEA:

  • Extraer ideaIU-2018.2.6.tar.gz en alguna carpeta.
  • Por consola ejecutar ./idea-IU-182.5107.16/bin/idea.sh.
  • Al momento de poner la licencia, seleccionar registración offline y pegar el código que está en Licencia IDEA hasta 2019-03-29.txt.
  • Una vez abierto, seleccionar Configure -> Create Desktop Entry.
  • Cerrar y abrirlo como un programa más de Ubuntu.

Instalar JDK 8 Oracle:

@cspinetta
cspinetta / ConfigReaders.scala
Created May 11, 2018 20:09
pureconfig ConfigReader for parsing TimeUnit values
import pureconfig.{ConfigReader, ConvertHelpers}
import scala.concurrent.duration.TimeUnit
trait ConfigReaders {
import ConvertHelpers._
implicit val dayOfWeekReader: ConfigReader[TimeUnit] =
ConfigReader.fromString[TimeUnit](catchReadError(s => TimeUnitConverter.timeUnit(s)))
}