Skip to content

Instantly share code, notes, and snippets.

@marcomalva
marcomalva / markdown-first-steps.md
Last active July 22, 2021 17:20
[markdown-first-steps] Markdown First Steps #markdown #introduction

%First Steps with Markdown %Marco Malva %2015/12/22 - 2021/05/18

Introduction

The format traditionally Markdown is now rebranded as commonmark. One can read more on commonmark here http://commonmark.org/

The commonly used suffix for markdown files is .md

@marcomalva
marcomalva / psql-list-active-queries.sql
Last active September 11, 2023 16:18
[PSQL - Active Queries] List Active Queries #psql
-- PostgreSQL: List the active queries
-- see also <https://gist.github.com/rgreenjr/3637525>
SELECT ROW_NUMBER() OVER() as rn
, a.datname
, a.usename
, a.client_addr
, a.pid
, age(clock_timestamp(), a.query_start) as age_start
, age(clock_timestamp(), state_change) as age_change
, a.wait_event
@marcomalva
marcomalva / psql-query-table-sizes.sql
Last active December 9, 2022 20:06
[PSQL - Query Table Sizes]Table/View Sizes #psql
--
-- PostgreSQL: query how larger tables (data + index) are
--
SELECT *, pg_size_pretty(total_bytes) AS total
, pg_size_pretty(index_bytes) AS INDEX
, pg_size_pretty(toast_bytes) AS toast
, pg_size_pretty(table_bytes) AS TABLE
, pg_size_pretty(sum(table_bytes) OVER(ORDER BY total_bytes)) AS table_total
, pg_size_pretty(sum(total_bytes) OVER(ORDER BY total_bytes)) AS db_total
FROM (
@marcomalva
marcomalva / postgres_queries_and_commands.sql
Last active September 22, 2021 19:36 — forked from rgreenjr/postgres_queries_and_commands.sql
[PostgreSQL Query Snippets] Useful PostgreSQL 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%'
@marcomalva
marcomalva / nomad-commands.sh
Last active December 9, 2022 20:00
[Nomad Commands]Useful nomad Commands #nomad #deploy
# various useful nomad commands
#
# listed in pseudo pet style, i.e. "<xyz>" prompts the user to supply a value for xyz
# * [GitHub - knqyf263/pet: Simple command-line snippet manager, written in Go.](https://github.com/knqyf263/pet)
# * [document cli command options](http://docopt.org/)
# * [Utility Conventions](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html#tag_12_01)
# list dead jobs that are not batch (periodic)
# any job listed indicates a failed deployment,
# that is a deployed job that did not remain running
@marcomalva
marcomalva / psql-count-connections.sql
Last active September 26, 2021 17:56
[PSQL - Count Number of Connections]Queries to obtain current/maximum count of connections with PostgreSQL #SQL
-- tuning advise: https://www.cybertec-postgresql.com/en/tuning-max_connections-in-postgresql/
--
-- get number of connections by database instance + total
select datname, count(*) as cnt_conn, sum(count(*)) over () as tot_conn from pg_stat_activity group by datname order by datname;
-- get more details, see column numbackends for number of connections
select * from pg_stat_database order by datname;
select datname, numbackends, sum(numbackends) over() as tot_conn from pg_stat_database order by datname;
@marcomalva
marcomalva / appimage-to-gnome-desktop-app.md
Created October 7, 2021 21:41
[AppImage to Gnome Desktop Application]Turn an appimage into a gnome desktop application #appimage #gnome3

Adding an AppImage as a Gnome Application

Six steps from donwloading an appimage to making it available as a Gnome desktop application. The examples assume that one stores the appimage files in folder /opt/var/AppImage/ but any folder will do.

  1. Download the appimage, e.g. cd /opt/var/AppImage/ && wget https://mirrors.mit.edu/kde/stable/digikam/7.3.0/digiKam-7.3.0-x86-64.appimage

  2. Set the executable bit, e.g. chmod u+x digiKam-7.3.0-x86-64.appimage

  3. Get an icon file (*.png) from the web, e.g. the github project page.

@marcomalva
marcomalva / copy2csv.sql
Created October 29, 2021 20:01
[PSQL - Parameterized \COPY TO CSV_FILE]Copy table/query to CSV File #SQL
-- copy2csv.sql: use psql to copy table or select query to CSV file with source and file as parameter
--
-- usage:
-- psql -v table_name="<table_name>" -v file_name="<file_name>" -h <host_name> -U <user_name> <db_name> -f copy2csv.sql
-- psql -v table_name="dummy" -v file_name="my_dummy.csv" -f copy2csv.sql
-- psql -v table_name="(select * from dummy order by birthdate desc)" -v file_name="my_dummy_2.csv" -f copy2csv.sql
--
-- idea from: https://postgrespro.com/list/thread-id/1893680
-- see also https://www.postgresqltutorial.com/postgresql-format/ for format command
--
@marcomalva
marcomalva / java-jvm-print-final-flags-grep-jvm-periodic-gc.sh
Last active December 15, 2021 22:36
[Java JVM - Print Flags Related To Periodic GC]JVM GC Added Periodic GC Option to Some GC Algorithms #java #jvm #gc
#!/bin/bash
#
# check for JVM flags pertaining periodic GC (uncommit, periodic, Shenandoa)
java -XX:+PrintFlagsFinal -version | grep -iE "uncommit|periodic|Shenandoa"
# and to show the JVM and OS settings as well the JVM version
java -XshowSettings:all -version
# testing with java8, java11 and java17
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -XX:+PrintFlagsFinal -version | grep -iE "uncommit|periodic|Shenandoa"
@marcomalva
marcomalva / gpg-snippets.sh
Created January 27, 2022 04:31
[gpg snippets sheet]GPG snippets #gpg #decrypt
# see also:
# * to export public key: <https://mirrors.tripadvisor.com/centos-vault/4.5/docs/html/rhel-sbs-en-4/s1-gnupg-export.html>
# * to extract private key to another machine: <https://makandracards.com/makandra-orga/37763-gpg-extract-private-key-and-import-on-different-machine>
# * to check key expiration date: <https://stackoverflow.com/questions/48914338/how-to-get-expiration-date-from-a-gpg-key>
# * to encrypt/decrypt: <https://www.gnupg.org/gph/en/manual/x110.html>
#
# list public keys
gpg --list-keys