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
/** | |
* REST exception handlers defined at a global level for the application | |
*/ | |
@ControllerAdvice | |
public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler { | |
private static final Logger log = LoggerFactory.getLogger(RestResponseEntityExceptionHandler.class); | |
/** | |
* Catch all for any other exceptions... | |
*/ |
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
//Inspired by https://gist.github.com/aerobless/37561bb0fb45b7e8732beaafad1cba26 | |
pipeline { | |
agent any | |
triggers { | |
//Needed by Bitbucket to see the builds on PRs https://stackoverflow.com/a/54710254 | |
pollSCM('') | |
} | |
stages { |
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
/** Shows how to use code to init data instead of using data.sql or import.sql with Spring Boot */ | |
@Component | |
@Profile({"local", "test"}) | |
@RequiredArgsConstructor //Lombok magic to autowire the final fields (optional) | |
public class LocalDataSetup implements ApplicationRunner { | |
private final MyObjectRepository myObjectRepository; | |
@Override | |
public void run(ApplicationArguments args) { |
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
//Config for s3 websync with cloudfront invalidation | |
// and Cache-Control headers for a Create-React-App application | |
//https://www.npmjs.com/package/websync | |
module.exports = { | |
source: "build/", | |
target: `s3://yourcompany-us-east-1-${process.env.CI_ENVIRONMENT_NAME}-createreactapp/`, | |
invalidateDeletes: true, | |
modifiers: { | |
"static/**": { CacheControl: "max-age=31536000" }, |
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
/** Based nearly completely on this same code from https://stackoverflow.com/a/52534584/1469525 */ | |
@Slf4j | |
public class ColumnRowMapper<T> extends BeanPropertyRowMapper<T> { | |
private ColumnRowMapper(final Class<T> mappedClass) { super(mappedClass); } | |
@Override | |
protected String underscoreName(final String name) { | |
final Column annotation; | |
final String columnName; |
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
@Service | |
class ClientJWTService { | |
@Value('${client.publicKey}') | |
String publicKeyString | |
@Value('${client.privateKey}') | |
String privateKeyString | |
Algorithm buildJwtAlgorithm() { | |
KeyFactory kf = KeyFactory.getInstance('RSA') |
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 ch.vorburger.mariadb4j.DBConfigurationBuilder | |
import ch.vorburger.mariadb4j.springframework.MariaDB4jSpringService | |
import org.springframework.beans.factory.annotation.Value | |
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder | |
import org.springframework.context.annotation.Bean | |
import org.springframework.context.annotation.Configuration | |
import org.springframework.context.annotation.Profile | |
import javax.sql.DataSource |
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
/** | |
* Useful when passing the browser timezone to a backend Java API that reads a timezone in using ZoneId.of(tz), | |
* as both 'America/Chicago' and '-0600' are valid values when passed to the Java API. | |
* The Offset is used to handle IE11 and other older browsers. | |
*/ | |
export const getUserTimeZoneOrOffset = () => { | |
let timeZone; | |
try { | |
timeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone; | |
} catch (error) { |
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 org.hibernate.jpa.HibernatePersistenceProvider; | |
import org.springframework.context.annotation.Configuration; | |
import javax.annotation.PostConstruct; | |
import javax.persistence.spi.PersistenceProvider; | |
import javax.persistence.spi.PersistenceProviderResolver; | |
import javax.persistence.spi.PersistenceProviderResolverHolder; | |
import java.util.Collections; | |
import java.util.List; |