Skip to content

Instantly share code, notes, and snippets.

@paoloantinori
paoloantinori / tempo_relativo.jinja2
Created June 5, 2021 08:38
Funzione helper da usarsi nei templates di Home Assistant per convertire le informazioni temporali relative dall'inglese all'italiano
{# Per testare basta copiare tutto questo nel tab Template dei Developer Tools#}
{# funzione helper per tradurre una data in tempo relativo #}
{%- macro trauduci_tempo(tempo) %}
{%- set testo = relative_time(tempo) %}
{{ relative_time(testo) | replace('seconds', 'secondi') | regex_replace('second\\b', 'secondo') | replace('minutes', 'minuti') | replace('minute', 'minuto') | replace('hours', 'ore') | replace('hour', 'ora') | replace('days', 'giorni')| replace('day', 'giorno') | replace('months', 'mesi') | replace('month', 'mese')}}
{%- endmacro %}
{# esempio di utilizzo #}
{{ trauduci_tempo(states.sensor.time.last_changed) }} fa.
@paoloantinori
paoloantinori / 80-mount-usb-to-media-by-label.rules
Created December 21, 2020 16:19 — forked from eklex/80-mount-usb-to-media-by-label.rules
udev rule for Home Assistant OS (hassio) to mount USB drives into the Supervisor Media directory
#
# udev rule
# Mount USB drive to the media directory using the partition name as mount point
#
# Description:
# Created for Home Assistant OS, this rule mounts any USB drives
# into the Hassio media directory (/mnt/data/supervisor/media).
# When a USB drive is connected to the board, the rule creates one directory
# per partition under the media directory. The newly created partition is named
# as the partition name. If the partition does not have a name, then the following
@paoloantinori
paoloantinori / 80-mount-usb-to-media-by-label.rules
Created December 21, 2020 16:19 — forked from eklex/80-mount-usb-to-media-by-label.rules
udev rule for Home Assistant OS (hassio) to mount USB drives into the Supervisor Media directory
#
# udev rule
# Mount USB drive to the media directory using the partition name as mount point
#
# Description:
# Created for Home Assistant OS, this rule mounts any USB drives
# into the Hassio media directory (/mnt/data/supervisor/media).
# When a USB drive is connected to the board, the rule creates one directory
# per partition under the media directory. The newly created partition is named
# as the partition name. If the partition does not have a name, then the following
@paoloantinori
paoloantinori / louketo.md
Last active June 11, 2020 08:23
How to protect Apicurio Registry (or any webapp) with Louketo Reverse Proxy, without modifying the code of your app.

how to protect Apicurio Registry with Louketo Reverse Proxy

# download the 3 servers we are going to use
podman pull quay.io/keycloak/keycloak
podman pull apicurio/apicurio-registry-mem

# louketo hasn't released a OCI image yet
# assuming you are on Linux. If not download the correct image
@paoloantinori
paoloantinori / limit_memory_with_cgroup.sh
Last active May 30, 2019 11:58
How to spawn a bash shell with limited memory limits .
sudo dnf install libcgroup-tools
export MY_CGROUP_NAME="java_build"
export MY_SUBSYSTEMS="memory"
# create cgroup according to above vars
sudo cgcreate -t $USER:$USER -a $USER:$USER -g $MY_SUBSYSTEMS:$MY_CGROUP_NAME
# lazily use this to calculate bytes: http://extraconversion.com/data-storage/gibibytes/gibibytes-to-bytes.html
MEMORY_VALUE_IN_BYTES=$(python -c 'print int(0.3 * 1024 * 1024 * 1024) ') # first number is the number of GiB
# configure cgroup limits
sudo cgset -r memory.limit_in_bytes=$MEMORY_VALUE_IN_BYTES $MY_CGROUP_NAME
In a nutshell, those components do not fetch data from the API, they just dispatch actions and subscribe to a granular slice of state served by a centralized store which lazy loads more instances of state as required.
The components there are just dummy components that implement ZERO business logic, they just render data, pushed by the Store using the Observer pattern.
When new user interactions happen, the components dispatch actions, which are stringly typed function classes. Those actions are intercepted by a reducer, which inspects the action type and its payload.
The reducer is obvlivious about WHO/WHAT dispatched that action and doesn't care.
It just selects if the action emitted is concerned to it (a web app can have dozens of isolated reducers working in parallel), inspects its payload, saves a snapshot of the state, clones the state, updates it according to the action payload, and replaces the former state snapshot with a new one.
The new state is reported through the store, so all components (
{
"items": [
{
"name": "Syndesis Extension - Groovy",
"description": "An extension to Syndesis to invoke Groovy Scripts inyour pipelines",
"extensionId": "io.syndesis.extensions:syndesis-extension-groovy",
"version": "1.0.0",
"tags": [
"dynamic",
"script"
@paoloantinori
paoloantinori / cgroups_java.sh
Last active December 15, 2017 15:18
Cgroups for java on Fedora
export MY_CGROUP_NAME="java_build"
export MY_SUBSYSTEMS="cpu,cpuacct"
sudo cgcreate -t $USER:$USER -a $USER:$USER -g $MY_SUBSYSTEMS:$MY_CGROUP_NAME
sudo cgset -r cpu.cfs_period_us=1000 $MY_CGROUP_NAME
sudo cgset -r cpu.cfs_quota_us=1000 $MY_CGROUP_NAME
# ls -al /sys/fs/cgroup/$MY_SUBSYSTEMS/$MY_CGROUP_NAME/
# cgexec seems not to work for me, so we are going to create explicitely a subshell and assign a cgroup to that process
bash
cgclassify -g $MY_SUBSYSTEMS:$MY_CGROUP_NAME $BASHPID

Integration Design

This is going to be a technical description of the idea concept of Integration and how its logical model is implemented.
It's not a comprehensive definition of how Syndesis work. We are not going to describe system pods and their respective responsibilities.

Data Model

Be aware that we currently don't have the logical model defined in any document or UML diagram. There is actually an ER Diagram here, but it's not reflecting entirely the current status of the information architecture.

The entry point for out model is the Integration entity, that represents an interaction between systems.

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.apache.org/schema/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<!-- Allows us to use system properties and fabric as variables in this configuration file -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="properties">
<bean class="io.fabric8.mq.fabric.ConfigurationProperties"/>
</property>
</bean>
<broker brokerName="${broker-name}" dataDirectory="${data}" restartAllowed="false" start="false" xmlns="http://activemq.apache.org/schema/core">
<destinationPolicy>
<policyMap>