Skip to content

Instantly share code, notes, and snippets.

View netstart's full-sized avatar

Clayton K. N. Passos netstart

View GitHub Profile
public class CollectionUtil {
/**
* Distinct by multiple fields – distinctByKeys() function
*
* <PRE>
* List<Record> list = recordsList.stream()
* .filter(distinctByKeys(Record::getId, Record::getName))
* .collect(Collectors.toList());
* </PRE>
@netstart
netstart / start-postgres-database.sh
Created July 31, 2019 13:27
start postgres database using docker
docker run --ulimit memlock=-1:-1 -it --rm=true --memory-swappiness=0 \
--name postgres-quarkus-rest-http-crud -e POSTGRES_USER=restcrud \
-e POSTGRES_PASSWORD=restcrud -e POSTGRES_DB=rest-crud \
-p 5432:5432 postgres:10.5
@netstart
netstart / Braces - EBANX
Last active June 10, 2019 19:42
Braces balanced solution
You are designing a compiler for a C++ program and need to check that braces in any given file are balanced.
Braces in a string are considered to be balanced if the following criteria are met:
All braces must be closed. Braces come in pairs of the form (), {} and []. The left brace opens the pair, and the right one closes it.
In any set of nested braces, the braces between any pair must be closed.
For example, [{}] is a valid grouping of braces but [{]} is not.
Function Description
Complete the function braces in the editor below. The function must return an array of strings where the string at each index i denotes whether or not the braces were balanced in values[i]. The array should consist of strings YES or NO aligned with their indices in values.
@netstart
netstart / AmazonSQSAsyncTest.java
Last active March 21, 2019 21:05
Porque todo programador deve ter conhecimento em diversas linguagens? Levando o conceito de Promisse para o Java ao utilizar CompletableFuture.
import cloud.localstack.utils.PromiseAsyncHandler;
import com.amazon.sqs.javamessaging.SQSConnection;
import com.amazon.sqs.javamessaging.SQSConnectionFactory;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.AmazonSQSAsync;
import com.amazonaws.services.sqs.model.*;
import com.amazonaws.services.sqs.model.Message;
import org.junit.Assert;
import org.junit.BeforeClass;
@netstart
netstart / TestAsyncUtils.java
Last active March 12, 2019 21:34
Trick to build AsyncClient for AWS services in LocalStack
import java.util.function.Supplier;
import cloud.localstack.TestUtils;
import cloud.localstack.docker.LocalstackDocker;
public class TestAsyncUtils extends TestUtils {
public static AmazonDynamoDBAsync getClientDynamoDBAsync() {
return AmazonDynamoDBAsyncClientBuilder.standard()
.withEndpointConfiguration(createEndpointConfiguration(LocalstackDocker.INSTANCE::getEndpointDynamoDB))
@netstart
netstart / background-image.ts
Created May 16, 2018 20:30 — forked from fer-ri/background-image.ts
Background Image Style Directive for Angular 2 and Ionic 2
import {Directive, ElementRef, Input} from '@angular/core';
@Directive({
selector: '[background-image]'
})
export class BackgroundImage {
private el: HTMLElement;
constructor(el: ElementRef) {
this.el = el.nativeElement;
@netstart
netstart / .travis.yml
Created February 1, 2018 19:03
Travis configuration to build angular project
language: node_js
sudo: required
node_js:
- node
before_script:
- "sudo chown root /opt/google/chrome/chrome-sandbox"
- "sudo chmod 4755 /opt/google/chrome/chrome-sandbox"
before_install:
@netstart
netstart / grow-message.service.ts
Last active December 26, 2017 14:27
A little abstraction to use Grow Message component from PrimeNG
import {Injectable} from '@angular/core';
import {MessageService} from 'primeng/components/common/messageservice';
/**
* A little abstraction to use Grow Message component from PrimeNG
* @see https://www.primefaces.org/primeng/#/growl
*
* Don't forget to use the tag <p-growl [(value)]="growlMessage" life="5000"></p-growl>
*
*/
@netstart
netstart / app.module.ts
Last active February 28, 2023 21:16
Forçar que o Angular utilize o locale pt-BR em uma aplicação.
// https://github.com/angular/angular-cli/issues/6683
import { NgModule, LOCALE_ID } from '@angular/core';
// force to use locale pt-BR
providers: [ {provide: LOCALE_ID, useValue: 'pt-BR' } ]
// Or use below line to get locale from browser
// providers: [ {provide: LOCALE_ID, useValue: window.navigator.language} ]
@netstart
netstart / clone-map.ts
Last active November 9, 2023 14:53
Example: How to clone Map with Array value in TypeScript
clone(mapIn: Map<number, Array<Product>>): Map<number, Array<Product>> {
let mapCloned: Map<number, Array<Product>> = new Map<number, Array<Product>>();
mapIn.forEach((products: Array<Product>, key: number, mapObj: Map<number, Array<Product>>) => {
//products.slice(0) clone array
mapCloned.set(key, products.slice(0));
});
return mapCloned;