Skip to content

Instantly share code, notes, and snippets.

View antoniomaria's full-sized avatar

Antonio Maria Sanchez Berrocal antoniomaria

View GitHub Profile
@antoniomaria
antoniomaria / .bash_profile
Created January 9, 2023 08:15
Development environment bash_profile
export BASH_SILENCE_DEPRECATION_WARNING=1
export LANG=en_US.UTF-8
export LC_ALL=$LANG
genpasswd() { pwgen -Bs $1 1 |pbcopy |pbpaste; echo “Has been copied to clipboard”
}
@antoniomaria
antoniomaria / script.sh
Created August 16, 2022 05:59
SSH Tunnel to AWS RDS or Aurora DB instance via EC2 instance
# Verify that you have access to your ec2 instance which has access to DB
ssh -i mykey.pem ec2-user@EC2_IP_ADDRESS
# Use tunnel port forwarding
ssh -i mykey.pem -L 3306:RDS-HOST-NAME:3306 ec2-user@IP-ADDRESS
# Connect to localhost
@antoniomaria
antoniomaria / SSLPoke.java
Last active January 14, 2022 10:37
SSLPoke
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.InputStream;
import java.io.OutputStream;
/**
* Establish a SSL connection to a host and port, writes a byte and
* prints the response. See
* @seen in http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services
*/
@antoniomaria
antoniomaria / DateTimeUtils.scala
Created December 8, 2020 08:09
Jodatime round to period
object DateTimeUtils {
import org.joda.time.format.ISODateTimeFormat
import org.joda.time.{DateTime, DateTimeZone, LocalDateTime, Period}
/**
* Round a given dateTime to next period. Examples
* <pre>
* 2018-04-10T09:59:59, 60m period -> 2018-04-10T10:00:00
* 2018-04-10T10:00:00, 60m period -> 2018-04-10T10:00:00
* 2018-04-10T10:00:01, 60m period -> 2018-04-10T11:00:00
* </pre>
@antoniomaria
antoniomaria / ReactiveStreamTcpClient.scala
Created October 2, 2019 06:13
Reactive Stream Tcp Client
import akka.actor.ActorSystem
import akka.event.{Logging, LoggingAdapter}
import akka.stream.ActorMaterializer
import akka.stream.scaladsl.{BidiFlow, Flow, Sink, Source, Tcp}
import akka.util.ByteString
import akka.{Done, NotUsed}
import org.slf4j.LoggerFactory
import scodec.bits.ByteVector
@antoniomaria
antoniomaria / sort.sh
Created August 20, 2016 16:31
Arrage photos by year/month folder using exiftool
# Execute within the folder where pictures are located.
# This command will create a directory hierarchy by year/year-month
sudo apt-get install libimage-exiftool-perl
exiftool -d %Y/%Y-%m/%Y-%m-%d-%H:%M:%S.%%e "-filename<datetimeoriginal" -r .
# See more
# http://ninedegreesbelow.com/photography/exiftool-commands.html#move
@antoniomaria
antoniomaria / build.gradle
Created April 12, 2016 06:46
Gradle Karaf assembly
apply plugin: 'base'
configurations {
runtime
paxlogback
}
dependencies {
runtime "org.apache.karaf:apache-karaf:$karafVersion@zip"
paxlogback "ch.qos.logback:logback-core:$logbackVersion@jar"
@antoniomaria
antoniomaria / Splitter.java
Created January 25, 2016 08:28
Java split bytes array into chunks
byte[] data = { 2, 3, 5, 7, 8, 9, 11, 12, 13 };
int blockSize = 3;
int blockCount = (data.length + blockSize - 1) / blockSize;
byte[] range = null;
for (int i = 1; i < blockCount; i++) {
int idx = (i - 1) * blockSize;
range = Arrays.copyOfRange(data, idx, idx + blockSize);
@antoniomaria
antoniomaria / log4j.xml
Created February 24, 2015 10:41
Log4j.xml file with location info for eclipse
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC
"-//APACHE//DTD LOG4J 1.2//EN" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
<log4j:configuration debug="false">
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="target" value="System.out" />
<param name="threshold" value="trace" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%t] %-5p %l %x - %m%n" />
@antoniomaria
antoniomaria / pom.xml
Last active August 29, 2015 14:13
UMLGraph Maven syntax
<!-- UMLGraph doclet -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<phase>pre-integration-test</phase>
<goals>
<goal>javadoc</goal>