20 December 2021

Sonar Java Injection

Rules not assigned by default, but very useful:

 - https://rules.sonarsource.com/java/RSPEC-3749
  Members of Spring components should be injected

- https://rules.sonarsource.com/java/RSPEC-4288
  Spring components should use constructor injection
 



13 November 2021

Algorithms and Data Structures for Massive Datasets

Technical Reviewer:

Dzejla Medjedovic, Emin Tahirovic, and Ines Dedovic
MEAP began July 2020 Publication in January 2022 (estimated)
ISBN 9781617298035 325 pages (estimated) printed in black & white

https://www.manning.com/books/algorithms-and-data-structures-for-massive-datasets



16 September 2021

netcat - nc

netcat
ncat
nc


-n : skip DNS lookups
-u : Use of UDP mode (instead of TCP)
-v : Extensive output
-w : timeout (seconds)
-z : Port scanner mode (zero I/O mode); only listening services are scanned (no data is sent)

Scan port 123 for NTP:
nc -z -v -u 0.us.pool.ntp.org 123


scan ports:
nc -w 2 -z 192.168.10.1 1-1024

nc -v -n 8.8.8.8 1-1000




30 July 2021

Miller's Madness

After 33 years:

COMPUTER RECREATIONS
A. K. Dewdney
Scientific American
Vol. 258, No. 5 (MAY 1988), pp. 118-121 (4 pages)

https://www.jstor.org/stable/24989094

22 July 2021

AWS Serverless Data Lake Framework

SDLF is a peculiar framework developed by AWS as a Data Lake using their services.

It is interesting how it creates two pipelines where the data is parsed (reduced), process as a big ETL, where finally can be exploited by BI products.

  • AWS Glue
  • S3
  • Lambda


https://sdlf.readthedocs.io/en/latest/index.html

https://sdlf.workshop.aws/en/

https://github.com/awslabs/aws-serverless-data-lake-framework



04 July 2021

Spring in Action, Sixth Edition

Beta tester:

+ Technical Proofer. (September 2021)

Craig Walls
MEAP began May 2020 Publication in Early 2022 (estimated)
ISBN 9781617297571 520 pages (estimated)

https://www.manning.com/books/spring-in-action-sixth-edition

02 July 2021

1. EKS Diagrams

Cluster > Node > Pod > Container


There are two types of nodes:

  • A Control-plane-node type, which makes up the Control Plane, acts as the “brains” of the cluster.

  • A Worker-node type, which makes up the Data Plane, runs the actual container images (via pods).

Pod A thin wrapper around one or more containers

DaemonSet Implements a single instance of a pod on a worker node

Deployment Details how to roll out (or roll back) across versions of your application

ReplicaSet Ensures a defined number of pods are always running

Job Ensures a pod properly runs to completion

Service Maps a fixed IP address to a logical group of pods

Label Key/Value pairs used for association and filtering













Cluster > Node > Pod > Container

A container runs typically as a single Unix process


















30 June 2021

EKS simple way

The simplest way to generate an AWS EKS

- install: awscli, eksctl, kubectl

 1.
eksctl create cluster -f cluster.yml
(it takes several minutes, 20 mins?)

cluster.yml:

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: my-kube-config
region: us-west-1
nodeGroups:
- name: node-group-1
desiredCapacity: 2
instanceType: t2.micro
ssh:
- name: node-group-2
desiredCapacity: 1
instanceType: t2.micro
ssh:
view raw cluster.yml hosted with ❤ by GitHub


2.
eksctl delete cluster --region=us-west-1 --name=my-kube-config


3.
eksctl get cluster

4.
kubectl config view

5.
//mandatory? (yep!)
aws eks update-kubeconfig --name <cluster-name>
aws eks update-kubeconfig --name cobroqr-eks-RCXW8qM5



6.
kubectl create deployment hello-node --image=k8s.gcr.io/echoserver:1.4

7.
kubectl get deployment

8.
kubectl get pods

9.
kubectl expose deployment hello-node --type=LoadBalancer --port=8080

10.
kubectl get services
(aca deberia aparecer el service nuevo agregado arriba en "expose" como LoadBalancer).
aca sale tb el EXTERNAL-IP para poder probar

11.
kubectl exec --stdin --tty hello-node-7567d9fdc9-6lbx4 -- /bin/bash
(del kubectl get pods)


12.
kubectl delete deployment --all
  deployment.apps "books-node" deleted
  deployment.apps "hello-node" deleted


13.
eksctl delete cluster --name <cluster-name>
eksctl delete cluster --name my-kube-config.us-west-1.eksctl.io




---------------------------

more examples:


6.
kubectl create deployment books-node --image=091501399925.dkr.ecr.us-west-1.amazonaws.com/ecr-eks-sandbox:latest

(al ver get deployment y get pods, veo que hay 1 pod por deploy...

9.
kubectl expose deployment books-node --type=LoadBalancer --port=8080


curl http://af760c2d8e8ff40608558465fa4a4a4e-710530633.us-west-1.elb.amazonaws.com:8080/books
(se demora en publicar)


12.
kubectl delete deployment --all



09 June 2021

cognado, da

 1. adj. Gram. Emparentado morfológicamente.

 

En Portugues es Cognato, y tenemos muchos cognados falsos

31 May 2021

The Checker Framework

 A peculiar static code analyzer.



import org.checkerframework.checker.nullness.qual.*;
import org.checkerframework.checker.tainting.qual.*;
/*
https://checkerframework.org/manual/#installation
javac.bat -processor TaintingChecker CheckerSimplePoc.java
TaintingChecker
FormatterChecker
NullnessChecker
UnitsChecker
RegexChecker
*/
public class CheckerSimplePoc {
private static final String ERROR_MESSAGE_HPAM_NOT_EXISTS = "No existe ningun registro en hpamMarca con id %s";
public static void main( @Tainted String[] args) {
@PolyTainted String aa = "xxxxxx";
String hola = String.format(ERROR_MESSAGE_HPAM_NOT_EXISTS, args[0]);
String hola2 = String.format(ERROR_MESSAGE_HPAM_NOT_EXISTS + aa);
System.out.format( aa );
System.out.format( args[0] );
System.out.println( hola );
System.out.println( String.format("%y", 7) );
// ------------------------
System.out.format(
args[0] + " not valid. HINT: %s",
args[1]
);
}
public void metodo(@Tainted String s) {
String hola = String.format(ERROR_MESSAGE_HPAM_NOT_EXISTS, s);
System.out.format( ERROR_MESSAGE_HPAM_NOT_EXISTS, s );
//System.out.println( String.format("%y", 7) );
}
}

07 May 2021

Solution to double partition Alphametics

Solution to double partition Alphametics, Knuth Donald, The Art of Computer Programming, Pre-Fascicle 2b, Generating All Permutations, Addison-Wesley, 12 June 2004, p. 42. http://www-cs-faculty.stanford.edu/~knuth/taocp.html#vol4

04 April 2021

Bcrypt Spring Security

From https://github.com/devwebcl/spring-samples

This simple sample to hash password using blowfish2a compatible with Postgres pgcrypto https://www.postgresql.org/docs/9.3/static/pgcrypto.html

It uses sample from http://docs.spring.io/spring-security/site/docs/current/apidocs/org/springframework/security/crypto/bcrypt/BCrypt.html

update: https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/crypto/bcrypt/BCrypt.html

 

 

package cl.devweb.spring.security.hashing.blowfish;
import org.springframework.security.crypto.bcrypt.BCrypt;
/*
* This simple sample to hash password using blowfish2a compatible with
* Postgres pgcrypto https://www.postgresql.org/docs/9.3/static/pgcrypto.html
*
*/
public class SpringSecurityTest {
public static void main(String[] args) {
String salt = BCrypt.gensalt(6);
System.out.println("salt:" + salt );
String password = "holamundo";
String stored_hash = "$2a$06$Rja8BGNHYDAQmWdDnaPZZeZDe1PzD8AUrwwyWurJ7t7qk7SDAjjyy";
// sample from http://docs.spring.io/spring-security/site/docs/current/apidocs/org/springframework/security/crypto/bcrypt/BCrypt.html
String hashed = BCrypt.hashpw(password, stored_hash);
System.out.println("hashed-pwd:" + hashed );
if (BCrypt.checkpw(password, stored_hash)) {
System.out.println("It matches");
} else {
System.out.println("It does NOT match");
}
}
}

18 February 2021

Apócope

En gramática, una apócope (del griego apokopé < apokopto, "cortar") es un metaplasmo donde se produce la pérdida o desaparición de uno o varios fonemas o sílabas al final de algunas palabras. Cuando la pérdida se produce al principio de la palabra se denomina aféresis, y si la pérdida tiene lugar en medio de la palabra se llama síncopa. Es una figura de dicción según la preceptiva tradicional. 

 

https://es.wikipedia.org/wiki/Ap%C3%B3cope

09 February 2021

Swagger to PDF/HTML5

     Pasos swagger:


    We need to have installed the following tools: swagger2markup and asciidoctor

  • brew install asciidoctor
  • brew install swagger2markup-cli    
  1.     get swagger.json with springboot up&running:
        http://127.0.0.1:8080/v2/api-docs
  2.     copy swagger.json
  3.     mkdir adocs
  4.     swagger2markup convert -i swagger.json -d adocs
  5.     modify overview.adoc (title =)
  6.     asciidoctor index.adoc
  7.     asciidoctor-pdf index.adoc



    $  cat index.adoc
    :doctype: book
    :toc: left
    :toclevels: 3
    :numbered:
    :hardbreaks:
    :sectlinks:
    :sectanchors:

    include::./overview.adoc[]
    include::./paths.adoc[]
    include::./security.adoc[]
    include::./definitions.adoc[]


29 January 2021

ICMP - Internet Control Message Protocol

https://stackoverflow.com/questions/21981796/cannot-ping-aws-ec2-instance

Add a new EC2 security group inbound rule:

  • Type: Custom ICMP rule
  • Protocol: Echo Request
  • Port: N/A
  • Source: your choice (I would select Anywhere to be able to ping from any machine)
The related ping utility is implemented using the ICMP echo request and echo reply messages. 
 
https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol

Function: Send ICMP ECHO_REQUEST to network hosts
Syntax: ping [-aAbBdDfhLnOqrRUvV6] [-c count] [-F...

 


14 January 2021

Java Copy Constructor

Sometimes we need to clone an object in Java, but not a reference (a junior developer may use). There are several ways to achieve this task; however, I recommend to use a copy-constructor (that comes from C++) and, in particular, using @Builder from Lombok (to avoid boilerplate code))

 



package cl.devweb.constructor;
public class Cliente implements Cloneable {
int rut;
String nombre;
Cliente(int rut, String nombre) {
this.rut = rut;
this.nombre = nombre;
}
// copy constructor
Cliente(Cliente c) {
System.out.println("Copy constructor");
rut = c.rut;
nombre = c.nombre;
}
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
public int getRut() {
return rut;
}
public void setRut(int rut) {
this.rut = rut;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
}
view raw Cliente.java hosted with ❤ by GitHub

package cl.devweb.constructor;
public class ClienteClonePoc {
public static void main(String[] args) {
try {
Cliente cliente1 = new Cliente(1, "joe");
Cliente cliente2 = (Cliente) cliente1.clone();
Cliente cliente3 = new Cliente(cliente1);
Cliente cliente4 = cliente1;
cliente1.setRut(7);
cliente1.setNombre("john");
System.out.println("cliente1: " + cliente1.getRut() + " " + cliente1.getNombre());
System.out.println("cliente2: " + cliente2.getRut() + " " + cliente2.getNombre());
System.out.println("cliente3: " + cliente3.getRut() + " " + cliente3.getNombre());
System.out.println("cliente4: " + cliente4.getRut() + " " + cliente4.getNombre());
} catch (CloneNotSupportedException c) {
c.printStackTrace();
}
}
}

package cl.devweb.constructor;
public class CopyConstructorPocLombok {
public static void main(String[] args) {
Premium premium1 = new Premium("pi", 3.14);
Premium premium2 = premium1.toBuilder().build(); //copy constructor
Premium premium3 = premium1;
premium1.setNameOption("e");
premium1.setPremiumValue(2.718);
System.out.println("premium1: " + premium1.getNameOption() + " " + premium1.getPremiumValue());
System.out.println("premium2: " + premium2.getNameOption() + " " + premium2.getPremiumValue());
System.out.println("premium3: " + premium3.getNameOption() + " " + premium3.getPremiumValue());
}
}

package cl.devweb.constructor;
import com.fasterxml.jackson.annotation.JsonAlias;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@Builder(toBuilder=true)
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class Premium {
@JsonAlias("nombreOpcion")
private String nameOption;
@JsonAlias("valor")
private double premiumValue;
}
view raw Premium.java hosted with ❤ by GitHub

Blog Archive

Disclaimer

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.