Skip to content

Instantly share code, notes, and snippets.

Avatar

Brett C. bmchild

View GitHub Profile
@bmchild
bmchild / Controller.java
Last active Sep 18, 2018
Example of how to wire up a chunked response and how to consume it via angular.
View Controller.java
@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 Jan 3, 2017
function to zip text + encrypt, 2 params (text to encrypt, filename w/o extension). Add to .bash_profile
View .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
}
View GetResourceContents.java
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 Aug 31, 2015
A Nonfunctional way of chaining java 8 Predicates together of different generic types.
View PredicateChain.java
package com.bmchild.utils;
import java.util.Objects;
import java.util.function.Predicate;
/**
* Non functional way of chaining predicates together
* @author brettchild
*
* @param <T>
View InterfaceConstant.java
public interface Employable {
String MY_CONSTANT = "value"
}
public class MyClass {
private String theConstant = Employable.MY_CONSTANT;
}
View jmx.txt
-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
View AbstractBatchCustomRepositoryImpl.java
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
View UserParameter.java
/*
* 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
}
View userQuery.sql
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)
-- ...
View User.java
@Entity
public class User {
@Id
private String userId;
private String lastName;
private String ssn;
// other fields and getter and setters
}
You can’t perform that action at this time.