Skip to content

Instantly share code, notes, and snippets.

Avatar

Marco Bergantin berga

View GitHub Profile
@berga
berga / import.sh
Created Jun 24, 2020 — forked from whistler/import.sh
Copy files to another repository while saving git history
View import.sh
# 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 — forked from andrewpage/report-passenger.rb
Report Phusion Passenger metrics to AWS CloudWatch.
View report-passenger.rb
#!/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 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
View postgres_queries_and_commands.sql
-- 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%'
View self-signed-certificate-with-custom-ca-for-home-assistant.md

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
View aws-ssm-ec2-proxy-command.sh
#!/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
View aws-ssm-ec2-proxy-command.sh
#!/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
#
View RDS get slowest query cloudwatch
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 / .promptrc
Created Feb 18, 2020 — forked from mortn/.promptrc
byobu git prompt
View .promptrc
#!/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.
#
@berga
berga / gist:ffdcaf4b6459f5a6463c1ea8d561b81f
Created Dec 19, 2019 — forked from knu/gist:111055
How to mass-rename tags and push them with Git
View gist:ffdcaf4b6459f5a6463c1ea8d561b81f
# 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 / test-cloud-init-run.sh
Created Nov 28, 2019 — forked from maoueh/test-cloud-init-run.sh
Small script to test changes made to cloud init config without rebooting
View test-cloud-init-run.sh
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
You can’t perform that action at this time.