Skip to content

Instantly share code, notes, and snippets.

Jeff Sheets jeffsheets

Block or report user

Report or block jeffsheets

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jeffsheets
jeffsheets / 1-websyncConfig.js
Last active Aug 13, 2019
AWS S3 Deploy sync w/ Cloudfront Invalidation and Cache-Control headers for Create-React-App
View 1-websyncConfig.js
//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 / .env.development
Last active Jun 26, 2019
JS to read AWS SSM variables for use in Gitlab CI process
View .env.development
#This is used locally by Create-React-App during development
#Cognito Region
REACT_APP_REGION=us-east-1
REACT_APP_USER_POOL_ID=us-east-1_youruserpoolid
REACT_APP_APP_CLIENT_ID=yourcognitoappclientidgoeshere
@jeffsheets
jeffsheets / GroovySqlWithOutputsAndResultSetRows.groovy
Last active Jun 5, 2019
Extend Groovy Sql with callWithRows method to call a Stored Procedure and process both Output Parameters and Rows from the ResultSet in the closure handler.Could be replaced if http://jira.codehaus.org/browse/GROOVY-3048 is ever completed
View GroovySqlWithOutputsAndResultSetRows.groovy
SqlHelper sql = new SqlHelper(dataSource)
List results = sql.callWithRows("{call ABC.FINDBYLAST($lastName, ${Sql.INTEGER}, ${Sql.VARCHAR})}") {
List<GroovyRowResult> rows, int status, String errorMessage ->
if (status != 0) {
throw new RuntimeException("Error received from stored proc $status : $errorMessage")
}
return rows
}
@jeffsheets
jeffsheets / _ReactIntl_CreatReactApp.md
Last active Apr 23, 2019
Create React App CRA2 with react-intl i18n message extraction and translation
View _ReactIntl_CreatReactApp.md

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

@jeffsheets
jeffsheets / AccountControllerTest.groovy
Created Jun 20, 2014
Spock test with Mocks of Spring MVC Rest Controller using standaloneSetup and mockMvc
View AccountControllerTest.groovy
import groovy.json.JsonSlurper
import org.springframework.test.web.servlet.MockMvc
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.http.HttpStatus.*
import spock.lang.Specification
/**
* A Spock Spring MVC Rest unit test that doesn't require a full spring context
*/
@jeffsheets
jeffsheets / SpringPropertiesConfig.java
Created Aug 14, 2014
Spring 4 Properties Java Configuration with Database-backed Properties along with File properties too
View SpringPropertiesConfig.java
/**
* Example of Spring 4 Properties Java Configuration,
* with a Database Properties table to store most values
* and a small application.properties file too.
* The Database table will take precedence over the properties file with this setup
*/
@Configuration
@PropertySource(value = { "classpath:application.properties" }, ignoreResourceNotFound=true)
public class SpringPropertiesConfig {
private static final Logger log = LoggerFactory.getLogger(SpringPropertiesConfig.class);
@jeffsheets
jeffsheets / ClientJWTService.groovy
Last active Oct 23, 2018
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
View ClientJWTService.groovy
@Service
class ClientJWTService {
@Value('${client.publicKey}')
String publicKeyString
@Value('${client.privateKey}')
String privateKeyString
Algorithm buildJwtAlgorithm() {
KeyFactory kf = KeyFactory.getInstance('RSA')
@jeffsheets
jeffsheets / GroovySQLWithSpringDAO.groovy
Last active Oct 19, 2018
Using Groovy SQL with Spring configured Datasource to call complicated stored procedures with multiple ResultSets and multiple In and Out Params
View GroovySQLWithSpringDAO.groovy
@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 / JsonDotNetLocalDateTimeDeserializer.groovy
Created Sep 26, 2018
Groovy Jackson Deserializer to convert a .NET style JSON dateTime to a Java LocalDateTime object
View JsonDotNetLocalDateTimeDeserializer.groovy
class JsonDotNetLocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
@Override
LocalDateTime deserialize(JsonParser parser, DeserializationContext ctxt) {
convertDotNetDateToJava(parser.text.trim())
}
/**
* Returns a Java LocalDateTime when given a .Net Date String
* /Date(1535491858840-0500)/
@jeffsheets
jeffsheets / ApiSecurityConfig.groovy
Created Sep 6, 2017
Spock Test for Spring Boot Security configuration - showing basic simple examples for unauthenticated users, role based access, and httpBasic logins
View ApiSecurityConfig.groovy
@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) {
You can’t perform that action at this time.