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 / gist:15bfad3d1bb7e9ab70f224158254f9be
Created November 12, 2019 13:16 — forked from danilop/gist:6d49e2b6507f748a00a9
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
@berga
berga / test-cloud-init-run.sh
Created November 28, 2019 10:16 — forked from maoueh/test-cloud-init-run.sh
Small script to test changes made to cloud init config without rebooting
rm -rf /var/lib/cloud/instance && rm -rf /var/lib/cloud/instances/* && rm -rf /var/lib/cloud/sem/*
cloud-init init && cloud-init modules --mode config && cloud-init modules --mode final
@berga
berga / gist:ffdcaf4b6459f5a6463c1ea8d561b81f
Created December 19, 2019 11:47 — forked from knu/gist:111055
How to mass-rename tags and push them with Git
# Rename tags named foo-bar-#.#.# to v#.#.# and push the tag changes
git tag -l | while read t; do n="v${t##*-}"; git tag $n $t; git push --tags ; git tag -d $t; git push origin :refs/tags/$t ; done
@berga
berga / .promptrc
Created February 18, 2020 09:30 — forked from mortn/.promptrc
byobu git prompt
#!/bin/bash
# modified from byobu's bashrc -- colorize the prompt
# Copyright (C) 2014 Dustin Kirkland
#
# Authors: Dustin Kirkland <kirkland@byobu.co>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
fields @timestamp, @message
| parse @message '*Query_time: * Lock_time: * Rows_sent: * Rows_examined: *\n*' as host, query_time, lock_time, rows_sent, rows_examined, query
| sort query_time desc
| limit 100
@berga
berga / aws-ssm-ec2-proxy-command.sh
Created March 24, 2020 10:41
AWS SSM SSH Proxy Command
#!/usr/bin/env sh
######## Usage #################################################################
#
# #1 Install the AWS CLI
# https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-install.html
#
# #2 Install the Session Manager Plugin for the AWS CLI
# https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html
#
@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

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 / 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%'
@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'