Skip to content

Instantly share code, notes, and snippets.

View prameshbhattarai's full-sized avatar

pramesh bhattarai prameshbhattarai

View GitHub Profile
@prameshbhattarai
prameshbhattarai / S3MultipartUpload.java
Last active July 2, 2024 18:55
Uploading InputStream to AWS S3 without Content-Length using Multipart Upload - JAVA
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.internal.Constants;
import com.amazonaws.services.s3.model.*;
import lombok.extern.log4j.Log4j2;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
@prameshbhattarai
prameshbhattarai / SubmitTask.java
Last active October 30, 2019 08:42
Executor Service: Submit method
public class SubmitTask {
private static final int DEFAULT_THREAD_COUNT = 4; // default number of threads
private final ThreadPoolExecutor executorService;
public SubmitTask() {
this.executorService = (ThreadPoolExecutor) Executors.newFixedThreadPool(DEFAULT_THREAD_COUNT);
}
// if we only submit task to executor service then our thread pool will not closed
@prameshbhattarai
prameshbhattarai / ExecuteTask.java
Last active October 30, 2019 08:42
Executor Service: Execute Method
package com.litmus;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* @author pramesh-bhattarai
@prameshbhattarai
prameshbhattarai / Area.java
Created October 9, 2019 11:55
Area of two intersected rectangle.
public class AreaOfRectangle {
public static long area(int length, int breadth) {
return Math.abs(length * breadth);
}
public static boolean isOverlapped(int K, int L, int M, int N,
int X, int Y) {
return K < X && X < M && L < Y && Y < N;
}
@prameshbhattarai
prameshbhattarai / build.gradle
Created July 24, 2019 06:46
creating jar file with dependencies in gradle
// creating jar file with all dependencies
jar {
manifest {
attributes "Main-Class": "PATH_TO_MAIN_CLASS"
}
from {
// filters only existing and non-empty dirs
sourceSets.main.runtimeClasspath
.filter { (it.isDirectory() && it.listFiles().length > 0) || it.isFile() }
@prameshbhattarai
prameshbhattarai / high-order-function.js
Created October 15, 2018 06:22
high order function in javascript
/*
* Chaining of map() and reduce() function
*/
(function() {
"use strict"
const object = [{id: 1, name: "normal object1"}, {id: 2, name: "normal object2"}, {id: 3, name: "normal object3"}]
const providers = [];
object.map(mapToProviderObject)
.reduce(pushFilteredProviders, providers);
@prameshbhattarai
prameshbhattarai / deep-object-select.js
Created October 15, 2018 06:20
search object in JSON object in javascript
(function() {
"use strict";
function searchByKeyPath(object, keys) {
var deep = keys.split("."), obj = null;
for(var i = 0; i < deep.length; i++) {
(obj == null) ? obj = '' + deep[i] : obj = obj + '.' + deep[i];
if((eval(obj) === null || eval(obj) === undefined) && (i !== deep.length-1)) {
var beforeNotFoundFrom = obj.substring(0, obj.lastIndexOf('.'));
throw "Object not found from " + obj;
@prameshbhattarai
prameshbhattarai / parse-link.js
Created October 15, 2018 06:18
parse link for pagination in javascript
@prameshbhattarai
prameshbhattarai / Callback.java
Created September 17, 2018 10:20
example of calling async callback function in java --fun--
package com.callback.fun;
import java.util.function.Consumer;
public class Callback {
private static final double salary = 75_000;
private static void getSalary(Consumer<Double> callback) {
System.out.println("get salary invoked");
@prameshbhattarai
prameshbhattarai / callback.js
Created September 10, 2018 11:20
example for how javascript callback works .....
const users = [
'Jack Howton',  
'Natividad Claussen',  
'Jasper Egner',  
'Adella Troxell',  
'Edda Methvin',  
'Aileen Chipley', 
'Kellee Viles'
];