Skip to content

Instantly share code, notes, and snippets.


MichailAlexakis drmalex07

  • IMIS "Athena" Research Center
  • Athens, Greece
View GitHub Profile
drmalex07 /
Last active Apr 12, 2021
Checkout subtree of a Git repository. #git #git-sparse-checkout #git-checkout

README - Checkout subtree of a Git subdirectory

See also:

Clone with a specific history depth (--depth) and start at the root of the repository (--sparse). You can also filter-out BLOB files. For example:

git clone --sparse --depth 1 --filter blob:none --branch master

Change directory into the newly-cloned repository and enable sparse-checkout mechanism (to fetch parts of the subtree in steps of increasing depth)

drmalex07 /
Last active Apr 12, 2021
Run flyway migration from a Docker container. #flyway

README - Run a Flyway migration from a Docker container

See also:

Prepare basic Flyway configuration (no sensitive data inside), say at config/flyway.conf:

# vim: set syntax=jproperties:
# See
flyway.schemas = foo
flyway.defaultSchema = foo
drmalex07 / read-line-with-prompt.c
Created Mar 12, 2021
Real lines in C without overflowing buffer. #C #fgets #read-line
View read-line-with-prompt.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const int MAX_LINE_SIZE = 10;
int main(int argc, char **argv){
char line[MAX_LINE_SIZE + 2];
drmalex07 /
Created Feb 6, 2021
Mimic escapism Python package in Java. #escapism
import java.util.Objects;
* Mimic escaping logic from Python {@code escapism} package.
public class Escapism
public static final String SAFE_CHARS = "abcdefghijklmnopqrstuvwxyz0123456789";
public static final char ESCAPE_CHAR = '-';
drmalex07 / weighted-graph.hpp
Created Nov 14, 2020
A simple weighted graph in C++. #c++ #graph #weighted-graph #minimum-spanning-tree #MST
View weighted-graph.hpp
#include <iostream>
#include <limits>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <stdexcept>
drmalex07 /
Last active Apr 11, 2021
Setup nullmailer. #smtp #nullmailer

README - Setup nullmailer

1. Prepare the inventory

An example inventory hosts.yml:

 # ...
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))}}'