Skip to content

Instantly share code, notes, and snippets.

@jeffsheets
jeffsheets / ContentTypeMappingJackson2HttpMessageConverter.java
Created August 5, 2015 18:02
A MappingJackson2HttpMessageConverter that forces the response Content-Type header to be application/json
public class ContentTypeMappingJackson2HttpMessageConverter extends MappingJackson2HttpMessageConverter {
/**
* Always set the Content-Type response header to application/json when using the Jackson message converter
*
* Without this there appears to be a conflict with Meteor/Atmosphere servlet that causes Spring
* to leave the Content-Type blank in the response
* https://groups.google.com/forum/#!topic/atmosphere-framework/uZOrfXl3Bu8
*/
@Override
@jeffsheets
jeffsheets / photoBackup.md
Last active May 31, 2018 01:09
Personal photo backup process

Personal Photo Backup Process

Just some notes so I can remember how I setup my phones to sync to my Crashplan backup on my PC

Requirements

  • Backup pics from multiple iPhones
  • The backup should be wireless and automatic (or close)
  • Backup all files on PC to Crashplan
  • Extra points for backing up new photos to the same place as existing old photos and camera photos
@jeffsheets
jeffsheets / PersonControllerIntProxiedSpec.groovy
Last active May 31, 2018 03:46
Spock 1.2 Spring Integration Test annotations SpringBean, SpringSpy, UnwrapAopProxy
import org.springframework.test.util.AopTestUtils
/** Showing how to unwrap the AOP proxy manually to reuse the cached Spring context config */
@Import([IntegrationTestMockingConfig])
class PersonControllerIntProxiedTest extends Specification {
@Autowired MockMvc mvc
/** A simple mock can just be autowired */
@Autowired ExternalRankingService externalRankingServiceMock
@jeffsheets
jeffsheets / SpringConsulRibbonContextPathConfig.groovy
Created June 14, 2018 16:57
Spring Config for RestTemplate to use contextPath from Consul
/**
* Workaround to let RestTemplate use the contextPath from Consul when calling URLs
* (instead of only using the host and port)
* See https://github.com/spring-cloud/spring-cloud-consul/issues/376
*
* Put this in any spring config class
*/
@Bean
LoadBalancerRequestTransformer consulContextPathTransformer() {
@jeffsheets
jeffsheets / gist:5292986
Last active July 20, 2018 14:39
Hibernate DetachedCriteria using subqueries exists clause, while eager fetching the lazy collection that is in the exists clause, and running via Spring HibernateTemplate findByCriteria, and limit results to max of 2000.
/*
* HQL would look something like this:
*
* from Person p join fetch p.addresses address
* where exists (
* from Address addr left join addr.state st
* where addr.personId = p.id
* and st.abbreviation = :abbreviation
* )
*/
@jeffsheets
jeffsheets / JsonDotNetLocalDateTimeDeserializer.groovy
Created September 26, 2018 19:24
Groovy Jackson Deserializer to convert a .NET style JSON dateTime to a Java LocalDateTime object
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 / GroovySqlWithOutputsAndResultSetRows.groovy
Last active June 5, 2019 15:35
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
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 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

@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 / 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}