Skip to content

Instantly share code, notes, and snippets.

@jeffsheets
jeffsheets / FakeComponent.test.js
Last active December 30, 2023 23:30
testing-library set and get a react-select value
import React from 'react';
import { screen, render } from '@testing-library/react';
import selectEvent from 'react-select-event';
import CountryComponent from './FakeComponent';
describe('CountryComponent Test', () => {
test('form has value of selected option', async () => {
render(<CountryComponent />);
// react-select let's us update the select value by label, but you must select it by role 'textbox' not a 'select'
@jeffsheets
jeffsheets / .env.development
Last active May 25, 2023 05:50
JS to read AWS SSM variables for use in Gitlab CI process
#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 / 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 / AccountControllerTest.groovy
Created June 20, 2014 20:18
Spock test with Mocks of Spring MVC Rest Controller using standaloneSetup and mockMvc
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 August 14, 2014 21:21
Spring 4 Properties Java Configuration with Database-backed Properties along with File properties too
/**
* 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 / email.html
Last active April 18, 2022 02:19
HTML Email structure and CSS hacks
<!--
* A collection of various HTML Email hacks
** Along with these, user an html boilerplate like https://github.com/seanpowell/Email-Boilerplate
** Hacks are from many sources including:
** https://litmus.com/blog/a-guide-to-bulletproof-buttons-in-email-design
** https://litmus.com/community/discussions/1007-outlook-image-sizes
** https://www.emailonacid.com/blog/article/email-development/how-to-code-emails-for-outlook-2016/
-->
<!-- 1) Fix image sizes in Outlook -->
@jeffsheets
jeffsheets / AutowiringSpringBeanJobFactory.java
Last active February 12, 2022 14:44
Configuring Quartz 2.1.7 with Spring 3.1.3 in clustered mode
/**
* Autowire Quartz Jobs with Spring context dependencies
* @see http://stackoverflow.com/questions/6990767/inject-bean-reference-into-a-quartz-job-in-spring/15211030#15211030
*/
public final class AutowiringSpringBeanJobFactory extends SpringBeanJobFactory implements ApplicationContextAware {
private transient AutowireCapableBeanFactory beanFactory;
public void setApplicationContext(final ApplicationContext context) {
beanFactory = context.getAutowireCapableBeanFactory();
}
@jeffsheets
jeffsheets / HibernatePersistenceProviderResolver.java
Created May 20, 2016 19:51
Use JPA 2.1 and Hibernate 4.3.11 on Websphere 8.5.5.x
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;
@jeffsheets
jeffsheets / timeZoneUtils.js
Last active November 5, 2021 02:49
Browser Javascript to get user timezone or offset that is IE11 safe when passed to a Java API, with Jest Test blogpost: https://www.sheetsj.com/2021/05/mock-intl-and-date-globals-in-jest.html
/**
* 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) {
@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