Skip to content

Instantly share code, notes, and snippets.

@bmchild
bmchild / Controller.java
Last active September 18, 2018 23:56
Example of how to wire up a chunked response and how to consume it via angular.
@RequestMapping(value = "/runJobAndGetLogs", method = RequestMethod.GET)
public ResponseEntity<StreamingResponseBody> runJobAndGetLogs() throws IOException {
final InputStream inputStream = someService.runJobAndGetReportProgress();
StreamingResponseBody body = StreamingResponseBody body = (outputStream) -> {
try (BufferedInputStream br = new BufferedInputStream(inputStream)) {
// just copying to the outputstream
byte[] contents = new byte[1024];
int bytesRead = 0;
while ((bytesRead = br.read(contents)) != -1) {
@bmchild
bmchild / .bash_profile
Created January 3, 2017 22:33
function to zip text + encrypt, 2 params (text to encrypt, filename w/o extension). Add to .bash_profile
#function to zip text + encrypt, 2 params (text to encrypt, filename w/o extension)
function zipe() {
echo "$1" > $2.txt && zip -e $2.zip $2.txt && rm $2.txt
}
String filePath = this.getClass().getClassLoader().getResource("folder/file.txt").getFile();
String fileContent = new String(Files.readAllBytes(Paths.get(filePath)), StandardCharsets.UTF_8);
@bmchild
bmchild / PredicateChain.java
Created August 31, 2015 14:57
A Nonfunctional way of chaining java 8 Predicates together of different generic types.
package com.bmchild.utils;
import java.util.Objects;
import java.util.function.Predicate;
/**
* Non functional way of chaining predicates together
* @author brettchild
*
* @param <T>
public interface Employable {
String MY_CONSTANT = "value"
}
public class MyClass {
private String theConstant = Employable.MY_CONSTANT;
}
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1234
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=127.0.0.1
@bmchild
bmchild / AbstractBatchCustomRepositoryImpl.java
Created February 18, 2015 15:47
Custom Batch Save Repository
package com.bmchild.data.shared.batch;
import javax.sql.DataSource;
import org.apache.commons.lang.Validate;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
/**
* @author bchild
/*
* Class used to filter the User entity
*/
public class UserParameter {
private String userId;
private String lastName;
/* only last 4 digits */
private String ssn;
// getters and setters
}
select *
from User
where
userId in (:userIds)
-- Then we need an OR clause for each match we want
OR ( lastName = :lastName1 AND SUBSTRING(ssn, LEN(ssn)-3, 4) = :lastFourSsn1)
OR ( lastName = :lastName2 AND SUBSTRING(ssn, LEN(ssn)-3, 4) = :lastFourSsn2)
-- ...
@Entity
public class User {
@Id
private String userId;
private String lastName;
private String ssn;
// other fields and getter and setters
}