This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Remove duplicate prime number in a list | |
*/ | |
for (int i = 0; i < list.size(); i++) { | |
if (Collections.frequency(list, list.get(i)) > 1) { | |
final Integer number = list.get(i); | |
if(LongStream.range(2, (long) Math.ceil(Math.sqrt(number + 1))).noneMatch(x -> number % x == 0)) | |
{ | |
list.remove(i); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to write to raw string with jackson 2? | |
String result =""; | |
try { | |
result = objectMapper.writeValueAsString(objectMapper.writeValueAsString(list)); | |
} catch (JsonProcessingException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
System.out.println(result); | |
//Output like this "[{\"id\":1,\"name\":\"Dinesh\",\"age\":20},{\"id\":2,\"name\":\"Kamal\",\"age\":15},{\"id\":3,\"name\":\"Vijay\",\"age\":25},{\"id\":4,\"name\":\"Dinesh\",\"age\":30},{\"id\":5,\"name\":\"Dinesh\",\"age\":18}]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static byte[] compress(BufferedImage image, float scale) throws IOException { | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg"); | |
ImageWriter writer = writers.next(); | |
ImageWriteParam param = writer.getDefaultWriteParam(); | |
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); | |
param.setCompressionQuality(scale); | |
ImageOutputStream ios = ImageIO.createImageOutputStream(baos); | |
writer.setOutput(ios); | |
writer.write(null, new IIOImage(image, null, null), param); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To Kill Port On Linux | |
========================== | |
kill $(lsof -t -i:8080) | |
To Move File to Other Location | |
============================= | |
mv command main options: | |
option description | |
mv -f force move by overwriting destination file without prompt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Add the Given Dependency | |
<dependency> | |
<groupId>com.amazonaws</groupId> | |
<artifactId>aws-java-sdk</artifactId> | |
<version>1.11.163</version> | |
</dependency> | |
*/ | |
import java.io.IOException; | |
import java.io.InputStream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Properties hibernateProperties() { | |
Properties properties = new Properties(); | |
properties.put(CommonConstants.HIBERNATE_DIALECT, | |
propertyReader.getProperty(CommonConstants.HIBERNATE_DIALECT)); | |
properties.put(CommonConstants.HIBERNATE_SHOW_SQL, | |
propertyReader.getProperty(CommonConstants.HIBERNATE_SHOW_SQL)); | |
properties.put(CommonConstants.HIBERNATE_FORMAT_SQL, | |
propertyReader.getProperty(CommonConstants.HIBERNATE_FORMAT_SQL)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mapToAoO = m => { | |
return Array.from(m).map( ([k,v]) => {return {[k]:v}} ); | |
}; | |
JSON.stringify(mapToAoO(map)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.ByteArrayInputStream; | |
import java.io.InputStream; | |
import java.util.UUID; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Component; | |
import com.amazonaws.services.s3.AmazonS3; | |
import com.amazonaws.services.s3.model.CreateBucketRequest; | |
import com.amazonaws.services.s3.model.GetBucketLocationRequest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.st.fileUplaod; | |
import java.io.File; | |
import com.amazonaws.auth.AWSStaticCredentialsProvider; | |
import com.amazonaws.auth.BasicAWSCredentials; | |
import com.amazonaws.regions.Regions; | |
import com.amazonaws.services.s3.AmazonS3; | |
import com.amazonaws.services.s3.AmazonS3ClientBuilder; | |
/*Add this Jar File |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RowCopy { | |
public static void main(String[] args) throws Exception { | |
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream("E:/budget-1.xls")); | |
HSSFSheet sheet = workbook.getSheet("Budget"); | |
copyRow(workbook, sheet, 5, 8); | |
copyRow(workbook, sheet, 6, 9); | |
FileOutputStream out = new FileOutputStream("E:/output.xls"); | |
workbook.write(out); | |
out.close(); |
OlderNewer