Skip to content

Instantly share code, notes, and snippets.

View MdGolam-Kibria's full-sized avatar
🎯
Focusing

Golam Kibria MdGolam-Kibria

🎯
Focusing
View GitHub Profile
@MdGolam-Kibria
MdGolam-Kibria / ReqResLoggingAspect.java
Created October 6, 2024 08:20
Request Response Details log globally using AOP including request served time calculation.
package com.bbl.corpnet.api.aspect;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
@MdGolam-Kibria
MdGolam-Kibria / RedisVsDatabase
Last active September 5, 2024 05:36
Redis Vs Database
----------------------------------------------------------------------Redis Over Database--------------------------------------------------------------------------------------------
The performance difference between a DB call (e.g., SQL database) and a Redis call (in-memory data store) can be significant due to the underlying architecture of each.
Key Differences in Speed:
Database Call (DB Call):
Nature: Most relational databases (like MySQL, PostgreSQL) store data on disk, though they may use some in-memory caching.
Latency: Typically, accessing data from disk is slower because of I/O overhead, indexing, and query execution time.
Average Response Time:
Milliseconds to seconds range, depending on the complexity of the query, indexing, and network latency.
@MdGolam-Kibria
MdGolam-Kibria / oracleTriggerExample.sql
Created August 22, 2024 08:57
Oracle PL/SQL trigger on table then update some column based on the trigger.
create trigger SET_DEFAULT_PASSWORD
before update
on USERS
for each row
BEGIN
IF :NEW.PASSWORD IS NOT NULL AND :NEW.PASSWORD <> :OLD.PASSWORD THEN
:NEW.PASSWORD := '$2a$10$fYcxMH5SzN.DtrF.t3IpgeG4JcYuBPkUZA06dqvjVyI23MVa46h3i';
:NEW.NUMBER_OF_BAD_LOGIN:=0;
--Default Password: Abc@12345
@MdGolam-Kibria
MdGolam-Kibria / pushDataToQueue.java
Created August 22, 2024 08:55
Push data to Rabbit MQ queue using java with publishing guarantee
public void produceBatchesDataToQueue(List<String> tranIDs, Integer eventId, String actionPoint) throws IOException, TimeoutException {
for (int i = 0; i < tranIDs.size(); i++) {
LOGGER_I.info("Going to bind actual request data");
JBCollectionPolicyModelRequest request = buildAarongApiCallbackModel(tranIDs.get(i), actionPoint);
request.setEventId(eventId);
String message = gson.toJson(request);
LOGGER_I.info("Successfully bind data and prepare message :{}", message);
@MdGolam-Kibria
MdGolam-Kibria / secondHighestSalary.java
Last active August 22, 2024 08:58
get second highest salary
public static void main(String[] args) {
int[] salaries = {100, 200, 500, 50, 30};
int secondHighestSalary = Arrays.stream(salaries)
.distinct() // Remove duplicates if any
.sorted()//30,50,100,200,500
.skip(salaries.length - 2) // Skip all without last 2 item = [200,500]
.findFirst()//200
.orElseThrow(null); // Throw an exception if no element is found
@MdGolam-Kibria
MdGolam-Kibria / 3rdHighAmount.sql
Created August 22, 2024 08:51
get 3rd high salary using ORACLE query
SELECT n.TOTAL_BBL_AMT FROM (SELECT TOTAL_BBL_AMT
FROM CORP_FILE_UPLOAD_INFO
order by TOTAL_BBL_AMT DESC) n offset 3 rows fetch next 1 rows only;
@MdGolam-Kibria
MdGolam-Kibria / RestClientApiCallExample.java
Created August 22, 2024 08:23
Api call using RestClient using java 17
public ResponseEntity<?> login(LoginRecord loginRecord) {
try {
RemoteRequest<LoginRecord> remoteRequest = new RemoteRequest<>();
remoteRequest.setRequestId(String.valueOf(System.nanoTime()));
remoteRequest.setChannelId("TERP");
remoteRequest.setRequestTimestamp(String.valueOf(System.currentTimeMillis()));
remoteRequest.setData(loginRecord);
log.info("""
[LOGIN] Going to call login api using
URL : {}
@MdGolam-Kibria
MdGolam-Kibria / addCodeInHtmlFromGithubGist.html
Last active August 22, 2024 08:59
Add code from github gist.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Embed Gist Example</title>
</head>
<body>
<h1>Example of Embedding a Gist</h1>
@MdGolam-Kibria
MdGolam-Kibria / NumberTOBanglaTranslation.java
Created August 22, 2024 06:48
Convert Number to Bangla Taka.
import java.text.DecimalFormat;
import java.util.Scanner;
public class NumberToBanglaTaka {
public static final String[] units = new String[]{"", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"};
public static final String[] tens = new String[]{"", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"};
public NumberToBanglaTaka() {
}
@MdGolam-Kibria
MdGolam-Kibria / RestTemplateExceptionHandleExample.java
Created August 22, 2024 06:46
Handle api call exceptions using RestTemplate.
private BaseResponseBody<?> handleExceptions(Exception e) {
try {
if (e instanceof HttpServerErrorException) {
if (((HttpServerErrorException) e).getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR) {
String responseBody500 = ((HttpServerErrorException) e).getResponseBodyAsString();
logger.error("[NSU] Nsu server return INTERNAL SERVER ERROR and the response body is : {}", responseBody500);
return ResponseBuilder.getFailureResponse(HttpStatus.SERVICE_UNAVAILABLE,
"NSU System did not respond as per our expectation. " +
"You can try again or you can proceed to collect using 'North South University (Offline)' merchant.", e);
}