Skip to content

Instantly share code, notes, and snippets.


MichailAlexakis drmalex07

View GitHub Profile
drmalex07 /
Created Sep 30, 2020
An oneshot systemd service for loading IPVS table. #ipvs #ipvsadm #virtual-servers #linux-virtual-servers #systemd

README - Restore IPVS table (systemd service)

Lets assume our IPVS table is saved under /usr/local/etc/ipvs-table (e.g. as the output of ipvsadm -S).

Create the service file at /etc/systemd/system/restore-ipvs-table.service:

Description=Restore IPVS table from file
drmalex07 /
Created Sep 19, 2020
Format a duration in Java, #java #duration
public class DurationToString
private final Duration duration;
private final TimeUnit unit;
private DurationToString(Duration d, TimeUnit u)
this.duration = d;
this.unit = u;
drmalex07 /
Last active May 13, 2020
Start a java process with enabled remote JMX connections. #java #jmx #jconsole


At server

In this example we launch an H2 server, but it doesnt matter; same for any Java process.

Create a password file at ~/.jmxremote.password using $JRE_HOME/lib/management/jmxremote.password as a template.

drmalex07 /
Last active May 10, 2020
Get Java heap usage. #java #heap #memory

README - Get Java heap usage

First, find PID of the Java process (e.g by using jps -lvm).

Use jstat to get measurements on the usage/capacity of the several memory pools of the heap (see also man jstat). The results are reported in kbytes.

Get heap capacity, usually referred to as commited size (i.e memory allocated from the OS), by summing up S0C, S1C, EC, OC columns:

jstat -gc ${pid} | gawk '{if (NR > 1) {printf("%.0fk\n", ($1 + $2 + $5 + $7))}}'
drmalex07 / func-returning-record.sql
Last active Apr 13, 2020
An example on plpgsql functions returning a (single) record. #postgres #plpgsql
View func-returning-record.sql
-- An example of a function returning a (single) record of (integer, integer, text)
CREATE OR REPLACE FUNCTION examine_change_of_status(
IN status text, IN prev_status text,
-- output parameters (correspond to fields of returned record)
OUT a_count integer, OUT b_count integer, OUT answer text)
AS $body$
drmalex07 /
Last active Jul 11, 2020
Setup docker registry. #docker #docker-registry

README - Setup Docker registry

Let's assume that the FQDN name of the server will be registry.localdomain, and the service will be exposed as https://registry.localdomain:8443/.

1. Prerequisites

Create an environment file .env for the docker-compose project. An example content:

drmalex07 / setup-docker-on-ubuntu.yml
Created Feb 21, 2020
An ansible playbook for setting-up Docker under Ubuntu. #docker #ansible
View setup-docker-on-ubuntu.yml
# Run with: ansible-playbook -b
- hosts: all
- command: lsb_release -is
register: lsb_release_distributor_result
drmalex07 /
Last active Feb 11, 2020
An example creating a Docker volume on NFS. #docker #nfs #docker-volumes

Readme - Create a Docker volume on NFS

In this example, we directly instruct Docker to maintain a volume backed by NFS storage. Another way, of course, is to mount the NFS folder at the system level (afterwards, any container can bind-mount it).

By adding a Docker volume backed by NFS, Docker engine will take care of mounting/unmounting based on how containers are using this volume.

See also this comment:

drmalex07 /
Last active Feb 9, 2020
Create bootable USB with Grub2. #grub #grub2 #boot #usb

README - Create bootable USB with GRUB2

Let /dev/sdb be the USB device. Create 1 VFAT partition at /dev/sdb1 and mount at /mnt/usb0.

Install GRUB on the device:

grub-install --boot-directory=/mnt/usb0/boot /dev/sdb

Now, all files needed by GRUB (e.g modules for filesystems) are under /mnt/usb0/boot/grub.

drmalex07 /
Last active Nov 26, 2019
A basic spreadsheet reader in Java. #xlsx #xls #spreadsheet #excel
package gr.auth.physics.magnetized.etl.util;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.IteratorUtils;
You can’t perform that action at this time.