Skip to content

Instantly share code, notes, and snippets.

View berga's full-sized avatar

Marco Bergantin berga

  • TIM - Gruppo Telecom Italia
  • Cagliari, Italy
View GitHub Profile
@berga
berga / curl-websocket.sh
Created October 25, 2022 10:04 — forked from htp/curl-websocket.sh
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/
@berga
berga / validate-yaml.txt
Created October 20, 2021 07:46 — forked from dmitryd/validate-yaml.txt
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/
@berga
berga / ansible_kms_encrypt_decrypt.md
Created October 11, 2021 10:44 — forked from darahayes/ansible_kms_encrypt_decrypt.md
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)

@berga
berga / ruby_galaxy_poker_pattern_matching.rb
Created April 7, 2021 15:00 — forked from baweaver/ruby_galaxy_poker_pattern_matching.rb
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 / README.md
Created February 20, 2021 23:25 — forked from gbraad/README.md
Import SSH-keys from GitHub

Import SSH-keys from GitHub

vagrant up
vagrant ssh -c "curl -L https://github.com/{your-username}.keys >> /home/vagrant/.ssh/authorized_keys"
@berga
berga / import.sh
Created June 24, 2020 11:12 — forked from whistler/import.sh
Copy files to another repository while saving git history
# copied from http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/
git clone <git repository A url> # clone source repository
cd <git repository A directory>
git remote rm origin # to make sure it doesn't affect the original repository
git filter-branch --subdirectory-filter <directory 1> -- --all # remove all files other than the ones needed
mkdir <directory 1> # move them into another directory where they will be stored in the destination repository (if needed)
mv * <directory 1>
git add .
git commit
@berga
berga / report-passenger.rb
Last active May 18, 2020 12:48 — forked from andrewpage/report-passenger.rb
Report Phusion Passenger metrics to AWS CloudWatch.
#!/usr/bin/env ruby
#
# Report Instance Count and Request Queue Size metrics from locally running Phusion Passenger instance.
# Author: Andrew Page <andrew@andrewpage.me>
# ==
# Phusion Passenger: https://www.phusionpassenger.com
require 'net/http'
require 'phusion_passenger'
require 'aws-sdk-cloudwatch'
@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%'

Create Root Certificate Authority and self-signed certificate for your Home Assistant. Compatible with Chrome browser > version 58, including the macOS Catalina 10.15 / iOS 13 (and above) new requirements.

Create Root Key

Attention: this is the key used to sign the certificate requests, anyone holding this can sign certificates on your behalf. So keep it in a safe place!

openssl genrsa -des3 -out rootCA.key 4096
@berga
berga / aws-ssm-ec2-proxy-command.sh
Last active March 24, 2020 10:49 — forked from rdkls/aws-ssm-ec2-proxy-command.sh
AWS SSM SSH ProxyCommand
#!/usr/bin/env bash
#
# Description
# Bootstrap SSH Session to an SSM-managed instance
# by temporarily adding a public SSH key available on the local machine (ssh-agent or in ~/.ssh)
#
#
# Installation
#
# First run your eye over this script to check for malicious code