Skip to content

Instantly share code, notes, and snippets.

View berga's full-sized avatar

Marco Bergantin berga

  • Lutech spa
  • Cagliari, Italy
View GitHub Profile
@berga
berga / dingtian-4ch.yaml
Created August 29, 2024 10:48 — forked from vladyspavlov/dingtian-4ch.yaml
ESPHome config for Dingtian 4CH Relay (dtwonder DT-R004) + Modbus NPN IO extender module
esphome:
name: dingtian-4ch
friendly_name: Dingtian 4CH
comment: "ESP32-D0WD v1.0"
# Change NPN module modbus speed to 19200
# Baud rate corresponds to the number: 0: 1200 1: 2400 2: 4800 3: 9600 4: 19200
#on_boot:
# ## configure controller settings at setup
# ## make sure priority is lower than setup_priority of modbus_controller
# priority: -100
@vladyspavlov
vladyspavlov / 1ch-relay.yaml
Last active August 29, 2024 10:56
ESPHome configuration for 1-channel ESP32 relay from AliExpress with a 90-250VAC power supply. SZHJW ESP32_Relay_AC X1_V1.1 (303E32AC111)
# https://www.aliexpress.com/item/1005005848983315.html
# Pinout:
# GPIO0 - Button
# GPIO16 - Relay
# GPIO23 - LED
# ESP: ESP32-WROOM-32E (ESP32-D0WD V3, rev. 3.1)
substitutions:
name: 1ch-relay
friendly_name: 1CH Relay
@vladyspavlov
vladyspavlov / dingtian-4ch.yaml
Last active March 28, 2025 09:01
ESPHome config for Dingtian 4CH Relay (dtwonder DT-R004) + Modbus NPN IO extender module
esphome:
name: dingtian-4ch
friendly_name: Dingtian 4CH
comment: "ESP32-D0WD v1.0"
# Change NPN module modbus speed to 19200
# Baud rate corresponds to the number: 0: 1200 1: 2400 2: 4800 3: 9600 4: 19200
#on_boot:
# ## configure controller settings at setup
# ## make sure priority is lower than setup_priority of modbus_controller
# priority: -100
@baweaver
baweaver / ruby_galaxy_poker_pattern_matching.rb
Created January 28, 2021 19:53
Variant of pattern matching example from RubyGalaxy talk
class Card
SUITS = %w(S H D C).freeze
RANKS = %w(2 3 4 5 6 7 8 9 10 J Q K A).freeze
RANKS_SCORES = RANKS.each_with_index.to_h
include Comparable
attr_reader :suit, :rank
def initialize(suit, rank)
@berga
berga / postgres_queries_and_commands.sql
Created May 14, 2020 22:16 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
#############################
### GENERATE CERT AND KEY ###
#############################
# when generating key and cert, use password provided by administrator
cd ~/Workspace/Silvermedia/vpn
kozak127@callisto:~/Workspace/Silvermedia/vpn$ openssl pkcs12 -in michal.wesoly.p12 -nocerts -nodes -out michal.wesoly.key
Enter Import Password:
@dmitryd
dmitryd / validate-yaml.txt
Last active February 8, 2022 10:15
Validate YAML file using Python one-liner
python -c 'import yaml,sys;yaml.safe_load(sys.stdin)' < file.yml
Needs "pip install pyyaml".
Source: https://liquidat.wordpress.com/2016/01/21/short-tip-verify-yaml-in-shell-via-python-one-liner/
@darahayes
darahayes / ansible_kms_encrypt_decrypt.md
Last active February 18, 2024 18:57
KMS Encrypt and Decrypt filters in Ansible

KMS Encrypt and Decrypt Filters for Ansible

This Gist shows how you can encrypt/decrypt variables with KMS during your Ansible playbook execution. While google searching I couldn't find anything useful on the subject.

Let's say your project has a folder of playbooks called plays.

In that folder, create a folder called filter_plugins and insert kms_filters.py (included in this gist)

@htp
htp / curl-websocket.sh
Last active February 8, 2025 05:24
Test a WebSocket using curl.
curl --include \
--no-buffer \
--header "Connection: Upgrade" \
--header "Upgrade: websocket" \
--header "Host: example.com:80" \
--header "Origin: http://example.com:80" \
--header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
--header "Sec-WebSocket-Version: 13" \
http://example.com:80/
@danilop
danilop / gist:6d49e2b6507f748a00a9
Created November 11, 2015 12:33
Amazon EC2 - user data to automatically mount an Amazon EFS file system at boot (Linux)
#cloud-config
package_upgrade: true
packages:
- nfs-utils
- httpd
- php
runcmd:
- echo "$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone).FILE_SYSTEM_ID.efs.us-west-2.amazonaws.com:/ /var/www/html/efs nfs4 defaults" >> /etc/fstab
- mkdir /var/www/html/efs
- mount -a