Skip to content

Instantly share code, notes, and snippets.

@jeffsheets
jeffsheets / ClientJWTService.groovy
Last active March 24, 2021 02:00
JWT creation in Spring Boot Groovy or Java with RSA 512 or 256 algorithm including steps to generate the keys stored as strings in yml properties file
@Service
class ClientJWTService {
@Value('${client.publicKey}')
String publicKeyString
@Value('${client.privateKey}')
String privateKeyString
Algorithm buildJwtAlgorithm() {
KeyFactory kf = KeyFactory.getInstance('RSA')
@jeffsheets
jeffsheets / PapioMenuAlexaAppPrivacyPolicy.txt
Last active February 19, 2021 19:55
Papio Menu Alexa App Privacy Policy
The Papio Menu Alexa app available on Amazon Alexa does NOT collect any information.
The app is free for anyone to use on Alexa
@jeffsheets
jeffsheets / ColumnRowMapper.java
Last active January 25, 2021 23:36
Use Spring JdbcTemplate to easily read data, without Spring Data JPA, and map columns using Column DTO mappings, using a secondary database connection
/** 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;
@jeffsheets
jeffsheets / 1-websyncConfig.js
Last active January 25, 2021 22:42
AWS S3 Deploy sync w/ Cloudfront Invalidation and Cache-Control headers for Create-React-App
//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" },
@jeffsheets
jeffsheets / LocalDataSetup.java
Last active December 31, 2020 14:50
Spring Boot Initialize Local Test Data on Startup
/** 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) {
@jeffsheets
jeffsheets / Jenkinsfile
Created December 8, 2020 22:31
Minimal Gradle Jenkinsfile
//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 {
@jeffsheets
jeffsheets / RestResponseEntityExceptionHandler.java
Last active October 31, 2020 11:44
Handle REST Exceptions in Spring
/**
* 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...
*/
@jeffsheets
jeffsheets / GroovySQLWithSpringDAO.groovy
Last active October 28, 2020 01:46
Using Groovy SQL with Spring configured Datasource to call complicated stored procedures with multiple ResultSets and multiple In and Out Params
@Slf4j
@Component
class GroovySQLWithSpringDAO {
@Autowired
Sql groovySql
List<GroovyRowResult> findByFirstLast(String firstName, String lastName) {
GString statement = """{call FIND_BY_FIRST_LAST_SP (
${firstName}, ${lastName}, 'SYSUSER',
${Sql.INTEGER}, ${Sql.VARCHAR}, ${Sql.VARCHAR}, ${Sql.VARCHAR}
@jeffsheets
jeffsheets / ApiSecurityConfig.groovy
Created September 6, 2017 16:33
Spock Test for Spring Boot Security configuration - showing basic simple examples for unauthenticated users, role based access, and httpBasic logins
@EnableWebSecurity
class ApiSecurityConfig extends WebSecurityConfigurerAdapter {
@Inject
void configureGlobal(AuthenticationManagerBuilder auth) {
auth.inMemoryAuthentication()
.withUser('svc_acct').password('somePassword').roles('FULL_ACCESS')
}
@Override
protected void configure(HttpSecurity http) {
@jeffsheets
jeffsheets / _ReactIntl_CreatReactApp.md
Last active December 30, 2019 22:41
Create React App CRA2 with react-intl i18n message extraction and translation

i18n Translations

To generate new translations:

  1. remove .messages folder
  2. Extract all messages into .messages dir with: yarn i18n:extract
  3. Add new messages into {lang}.json files with: yarn i18n:manageTranslations
  4. Translate any new entries in {lang}.json files and commit to repo (see Untranslated keys: output of previous command for list of keys needing translation)

Setup