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 / 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 / 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 / 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 / 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 / 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 / .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 / _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