Skip to content

Instantly share code, notes, and snippets.

Avatar

MichailAlexakis drmalex07

  • IMIS "Athena" Research Center
  • Athens, Greece
View GitHub Profile
@drmalex07
drmalex07 / DelayQueueExample.java
Created January 14, 2023 22:00
An example with DelayQueue in Java. #DelayQueue #java
View DelayQueueExample.java
import java.time.Duration;
import java.util.concurrent.Callable;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class DelayQueueExample
{
@drmalex07
drmalex07 / README-git-checkout-a-subtree.md
Last active April 12, 2021 21:17
Checkout subtree of a Git repository. #git #git-sparse-checkout #git-checkout
View README-git-checkout-a-subtree.md

README - Checkout subtree of a Git subdirectory

See also: https://unix.stackexchange.com/questions/233327/is-it-possible-to-clone-only-part-of-a-git-project

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 https://github.com/NowhereLand/helloworld

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

@drmalex07
drmalex07 / README-flyway-migration-from-docker.md
Last active April 12, 2021 14:12
Run flyway migration from a Docker container. #flyway
View README-flyway-migration-from-docker.md

README - Run a Flyway migration from a Docker container

See also: https://flywaydb.org/documentation/configuration/configfile

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

# vim: set syntax=jproperties:
# See https://flywaydb.org/documentation/configuration/configfile
flyway.schemas = foo
flyway.defaultSchema = foo
@drmalex07
drmalex07 / read-line-with-prompt.c
Created March 12, 2021 23:31
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
drmalex07 / Escapism.java
Created February 6, 2021 00:52
Mimic escapism Python package in Java. #escapism
View Escapism.java
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
drmalex07 / weighted-graph.hpp
Created November 14, 2020 23:15
A simple weighted graph in C++. #c++ #graph #weighted-graph #minimum-spanning-tree #MST
View weighted-graph.hpp
#ifndef _WEIGHTED_GRAPH_HPP
#define _WEIGHTED_GRAPH_HPP 1
#include <iostream>
#include <limits>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <stdexcept>
@drmalex07
drmalex07 / README-setup-nullmailer.md
Last active April 11, 2021 13:02
Setup nullmailer. #smtp #nullmailer
View README-setup-nullmailer.md

README - Setup nullmailer

1. Prepare the inventory

An example inventory hosts.yml:

---
all:
  vars:
    # ...
@drmalex07
drmalex07 / README-restore-ipvs-table.md
Created September 30, 2020 11:08
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 September 19, 2020 11:22
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 11:24
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