Skip to content

Instantly share code, notes, and snippets.

@ToanPV90
ToanPV90 / RestTemplateHelper.java
Created June 15, 2023 05:32 — forked from slmanju/RestTemplateHelper.java
Generic RestTemplate wrapper
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.CollectionType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;

This recipe is a work in progress and has never been run as-is.

  • timeouts are in ms
  • lock timeout: in postgres, when a statement that wants a restrictive lock waits on another lock, other statements that want locks can't jump the queue. so even though the statement that is waiting might only take a very short amount of time, when it starts running, while it is waiting no other statements can begin. So we set the lock timeout pretty low and retry if we don't get it.
  • statement timeout: we set a short statement timeout before statements which do lock and which we expect to take a short amount of time, just in case something about our assumptions/understanding is wrong and the statement ends up taking a long time. if this happens the statement will bail early without causing harm, and we can investigate what is wrong with
@ToanPV90
ToanPV90 / multiple_ssh_setting.md
Created June 2, 2022 06:35 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
font Menlo for Powerline Terminal VS code
git clone https://github.com/abertsch/Menlo-for-Powerline.git
sudo mv Menlo*.tff /usr/share/fonts
It's Varargs :)
The varargs short for variable-length arguments is a feature that allows the method to accept variable number of arguments (zero or more). With varargs it has become simple to create methods that need to take a variable number of arguments. The feature of variable argument has been added in Java 5.
Syntax of varargs
A vararg is secified by three ellipsis (three dots) after the data type, its general form is
return_type method_name(data_type ... variableName){
}
List images
$ docker images -a
Run container with mapping port
$ docker run -d -p {localhost-port}:{container-port} image_name
Removing images according to a pattern
$ docker images -a | grep "pattern" | awk '{print $3}' | xargs docker rmi -f
Removing all images
@ToanPV90
ToanPV90 / update-git.sh
Created February 13, 2020 09:56 — forked from YuMS/update-git.sh
Update git to latest version on Ubuntu
#!/bin/bash
sudo add-apt-repository -y ppa:git-core/ppa
sudo apt-get update
sudo apt-get install git -y
@ToanPV90
ToanPV90 / postgres-cheatsheet.md
Created January 25, 2020 06:52 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@ToanPV90
ToanPV90 / DateTimeUtil.java
Created January 20, 2020 07:25 — forked from dassiorleando/DateTimeUtil.java
A JodaTime and java.util.Date Util Class with a lot of usefull functions.
package cm.flashbusiness.core.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.joda.time.DateTime;
/**
* @author dassi
@ToanPV90
ToanPV90 / log
Created July 31, 2019 17:54
git log oneline
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commi