Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / exportImportJavaCert.md
Last active April 6, 2023 16:29
Bash Commands to Export Cert and Import into Java Truststore

Command to export a cert from a website to a .cer file (example uses google.com) Tested with git-bash shell on Windows. Assume similar on Mac?

openssl s_client -servername google.com -connect google.com:443 </dev/null 2>/dev/null | openssl x509 -inform PEM -outform DER -out google.com.cer

Command to import into local java truststore (use your own location of JAVA_HOME)

"$JAVA_HOME"/bin/keytool -keystore "$JAVA_HOME"/lib/security/cacerts -importcert -alias google.com -file google.com.cer

@jeffsheets
jeffsheets / GwtSpockWidgetSpec.groovy
Last active April 30, 2018 21:27
GWT Spock test with GwtMockito for Google Web Toolkit client testing
package com.sheetsj.myapp.client.widget.fancy
import com.google.gwt.event.dom.client.KeyUpEvent
import com.google.gwt.user.client.ui.Widget
import com.google.gwtmockito.GwtMockito
import com.sheetsj.myproj.client.AppController
import com.sheetsj.myproj.client.widget.ErrorWidget
import org.mockito.Mockito
import spock.lang.Specification
@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 / EmbeddedMariaDbConfig.groovy
Last active April 26, 2021 12:31
Embedded MariaDB4j Spring Boot Configuration
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