Skip to content

Instantly share code, notes, and snippets.

Avatar

Pablo Fabricio Lettieri fabri1983

View GitHub Profile
@fabri1983
fabri1983 / MiniString.java
Last active Dec 30, 2019
Encoded a 10 max length String with up to 64 different characters (using 6 bits per character) in a long type (64 bits).
View MiniString.java
/**
* Encoding a string into a long.
* <br/>
* Squeeze a String inside a long type, although we need to accept some limitations.
* <br/>
* The long type has 64 bits, so using a base 64 encoding (6 bits) we can store up to 10 characters inside.
* <br/>
* We assume that the target String has a maximum length of 10 characters and they are composed only
* of uppercase letters, numbers and a limited number of special characters.
*/
@fabri1983
fabri1983 / WeekOfDayNextToK.java
Created Oct 2, 2019
Given a set of week days and a positive integer K, find the week of day which follows a day plus K days.
View WeekOfDayNextToK.java
/**
* Given the next set of week of days as strings in the given order: <code>Mon, Tue, Wed, Thu, Fri, Sat, Sun</code> <br/>
* and given a positive integer <code>K</code> in the range <code>[0..500]</code>. <br/>
* Find the week of day for a given day plus K days.<br/>
* For example:<br/>
* <code>Wed + 5 = Mon</code>
* <code>Sun + 0 = Sun</code>
* <code>Tue + 28 = Tue</code>
* <br/><br/>
* Max time for resolution: 15 minutes.
@fabri1983
fabri1983 / SmallestPositiveIntegerNotOccurring.java
Created Oct 2, 2019
Given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.
View SmallestPositiveIntegerNotOccurring.java
/**
* Write a function that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A. <br/>
* For example, given <code>A = [1, 3, 6, 4, 1, 2]</code>, the function should return 5. <br/>
* Given <code>A = [1, 2, 3]</code>, the function should return 4. <br/>
* Given <code>A = [-1, -3]</code>, the function should return 1. <br/>
* <br/>
* Write an efficient algorithm for the following assumptions: <br/>
* N is an integer within the range <code>[1..100,000]</code>. <br/>
* Each element of array A is an integer within the range <code>[-1,000,000..1,000,000]</code>. <br/>
* <br/>
@fabri1983
fabri1983 / Ipv4CombinationsCounter.java
Last active Oct 14, 2019
Given a string S containing a sequence of positive integers, count how many valid IPv4 addresses it contains.
View Ipv4CombinationsCounter.java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Given a string S containing a sequence of positive integers,
* count how many valid IPv4 addresses it contains. <br/>
* Example: <br/>
* S="1234" contains: 1.2.3.4 so count=1 <br/>
* S="5255255255" contains: 5.255.255.255 and 52.55.255.255 so count=2 <br/>
@fabri1983
fabri1983 / change-docker-machine-ip.bat
Last active Sep 11, 2019
Change Docker Machine IP address on Windows for Docker Tool Box
View change-docker-machine-ip.bat
@echo off
setlocal enabledelayedexpansion
:: Usage:
:: This scripts change a docker machine's ip address created using Docker Tool Box.
:: NOTE: you need to run ifconfig on machine instance to know whether interface you want to modify: eth0 or eth1
:: Eg for default machine:
:: First you need to start the default docker machine
:: docker-machine start default
:: Secondly change IP address:
@fabri1983
fabri1983 / docker-build.bat
Last active Sep 11, 2019
Script docker-build expects two arguments: artifact name (war filename without extension) and docker tag name.
View docker-build.bat
@ECHO OFF
IF "%1"=="" (
GOTO NO_ARGS
)
IF "%2"=="" (
GOTO NO_ARGS
)
IF NOT "%3"=="" (
GOTO WRONG_ARGS
@fabri1983
fabri1983 / Dockerfile_2
Last active Sep 11, 2019
Multi stage Docker file for image creation based on Alpine Linux, Tomcat native, OpenJDK 12 custom JRE (jlink), and FFMPEG 4.x. WAR file has to be decompressed outside.
View Dockerfile_2
# OpenJDK 12 alpine jdk/jre uses alpine 3.10.
# Visit https://github.com/AdoptOpenJDK/openjdk-docker/tree/master/12
######################################################################################################
FROM adoptopenjdk/openjdk12:alpine AS STAGING-TOMCAT
############# INSTALL NATIVE TOMCAT #############
ENV CATALINA_HOME=/opt/tomcat \
TOMCAT_MAJOR="8" \
TOMCAT_VERSION="8.5.43"
@fabri1983
fabri1983 / Dockerfile_1
Last active Sep 11, 2019
Multi stage Docker file for image creation based on Alpine Linux, Tomcat native, OpenJDK JRE, and FFMPEG 4.x. WAR file has to be decompressed outside.
View Dockerfile_1
# OpenJDK 12 alpine jdk/jre uses alpine 3.10.
# Visit https://github.com/AdoptOpenJDK/openjdk-docker/blob/master/12/jre/alpine/Dockerfile.hotspot.releases.full
######################################################################################################
FROM alpine:3.10 AS STAGING-TOMCAT
LABEL maintainer="fabri1983dockerid"
############# INSTALL NATIVE TOMCAT #############
ENV CATALINA_HOME=/opt/tomcat \
@fabri1983
fabri1983 / MainHelloWorldNative.java
Last active Sep 11, 2019
Java class for testing usage of fork-join Actions by GraalVM native image generation.
View MainHelloWorldNative.java
package org.fabri1983.eternity2.forkjoin_solver;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveAction;
/**
* This class intended for testing use of fork-join Actions in Graal native image generation.
* Building steps:
* <pre>
@fabri1983
fabri1983 / MaxDifference.java
Last active Sep 11, 2019
Max Difference - Java
View MaxDifference.java
package org.fabri1983.maxdifference;
import java.util.Arrays;
import java.util.List;
/**
* Given an array of integers, compute the maximum difference between any item
* and any lower indexed smaller item for all the possible pairs.
* In other words, for the array arr, find the maximum value arr[j] - arr[i]
* for all i,j where 0 <= i < j < n and arr[i] < arr[j].