Skip to content

Instantly share code, notes, and snippets.

Avatar

MichailAlexakis drmalex07

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

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:

[Unit]
Description=Restore IPVS table from file
After=network.target
@drmalex07
drmalex07 / DurationToString.java
Created Sep 19, 2020
Format a duration in Java, #java #duration
View DurationToString.java
public class DurationToString
{
private final Duration duration;
private final TimeUnit unit;
private DurationToString(Duration d, TimeUnit u)
{
this.duration = d;
this.unit = u;
@drmalex07
drmalex07 / README-launch-java-with-enabled-remote-jmx.md
Last active May 13, 2020
Start a java process with enabled remote JMX connections. #java #jmx #jconsole
View README-launch-java-with-enabled-remote-jmx.md

README

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.

JMX_PORT=1616
@drmalex07
drmalex07 / README-java-heap-usage.md
Last active May 10, 2020
Get Java heap usage. #java #heap #memory
View README-java-heap-usage.md

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
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$
BEGIN
@drmalex07
drmalex07 / README-setup-docker-registry.md
Last active Jul 11, 2020
Setup docker registry. #docker #docker-registry
View README-setup-docker-registry.md

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:

COMPOSE_PROJECT_NAME=registry_localdomain
@drmalex07
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
pre_tasks:
- command: lsb_release -is
register: lsb_release_distributor_result
@drmalex07
drmalex07 / README-docker-nfs-volume.md
Last active Feb 11, 2020
An example creating a Docker volume on NFS. #docker #nfs #docker-volumes
View README-docker-nfs-volume.md

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
drmalex07 / README-bootable-usb-with-grub2.md
Last active Feb 9, 2020
Create bootable USB with Grub2. #grub #grub2 #boot #usb
View README-bootable-usb-with-grub2.md

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
drmalex07 / AbstractSpreadsheetReader.java
Last active Nov 26, 2019
A basic spreadsheet reader in Java. #xlsx #xls #spreadsheet #excel
View AbstractSpreadsheetReader.java
package gr.auth.physics.magnetized.etl.util;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.IteratorUtils;
import org.apache.poi.ss.usermodel.Cell;
You can’t perform that action at this time.