Skip to content

Instantly share code, notes, and snippets.

View twasink's full-sized avatar

Robert Watkins twasink

View GitHub Profile
@twasink
twasink / MockSpikes.js
Created April 2, 2024 21:51
Jest and Mocks and React, oh my.
/**
* @jest-environment jsdom
*/
import { render } from '@testing-library/react';
import '@testing-library/jest-dom';
/*
* The simplest way to mock an import. The `jest.mock` function takes 3 arguments:
* * the path to the module to import (relative or absolute; either works)
* * a "factory function" that returns the function that the module is meant to provide
@twasink
twasink / Description
Created June 6, 2012 11:55
Spring, Hibernate, HSQLDB and automatically creating tables
An example of using Spring and Hibernate together to automatically create a HSQLDB in-memory database for testing hibernate mappings.
@twasink
twasink / AssociativeReader.js
Created April 16, 2013 00:33
ExtJS has some really nice support out of the box for converting JSON data to model objects. However, it only supports array-based associations, and doesn't support maps/associative arrays. The AssociativeReader - included here, along with two demo models and sample data - provides a way to do that.
/**
* A variant of the JSON reader. Instead of reading arrays, where each record in the array field
* has an 'id' property, it reads objects - aka associative arrays. The key of the entry will be the
* array.
*
* So where the JSON reader would like data like this:
* [ { id: '1', property: 'foo' }, { id: '2', property: 'bar' } ]
*
* the associative reader likes data like this:
* { '1': { property: 'foo' }, '2': { property: 'bar' } }
@twasink
twasink / Jenkins-Dockerfile
Last active June 25, 2021 06:20
Jenkins Image, using Docker-in-Docker
# We need Ruby to do a lot of stuff; let's install it here
# Using buster because that's what the Jenkins build is based on.
FROM ruby:2.7-buster as ruby
COPY --from=ruby / /
FROM jenkins/jenkins:lts-jdk11
MAINTAINER Robert Watkins
USER root
@twasink
twasink / Jenkins.yaml
Last active June 25, 2021 06:20
Jenkins ECS CloudFormation
AWSTemplateFormatVersion: 2010-09-09
Description: Jenkins ECS Service
# This configures a Jenkins instance, using a custom Docker image,
# running as a container on Amazon's ECS.
Parameters:
AvailabilityZone:
Type: AWS::EC2::AvailabilityZone::Name
Default: us-east-1a
@twasink
twasink / nexus.yaml
Created June 20, 2021 22:29
Nexus ECS CloudFormation
AWSTemplateFormatVersion: 2010-09-09
Description: Nexus ECS Service
# This configures a Sonatype Nexus 3 instance, running as a container on Amazon's ECS.
# This particular version is part of an ecosystem where other resources,
# such as a DNS zone and load balancer, are already created.
# These are referred to with !ImportValue statements
Parameters:
AvailabilityZone:
@twasink
twasink / AjaxErrorHandlingSpikeSpec.js
Created September 16, 2019 13:17
An attempt to explore how error handling in ExtJS AJAX requests work. Use ExtJS, Jasmine
/**
* An attempt to explore how error handling in ExtJS AJAX requests work,
* in particular looking at ways to re-try requests and cope with
* both the conventional 'success/fail/callback' style and this
* new-fangled 'then/always/otherwise' promise approach.
*/
describe("Twasink.spike.AjaxErrorHandlingSpikeSpec", function() {
var successHandler;
var failHandler;
var alwaysHandler;
#!groovy
node {
// Need to replace the '%2F' used by Jenkins to deal with / in the path (e.g. story/...)
// because tests that do getResource will escape the % again, and the test files can't be found
ws("workspace/${env.JOB_NAME}/${env.BRANCH_NAME}".replace('%2F', '_')) {
// Mark the code checkout 'stage'....
stage 'Checkout'
checkout scm
// Mark the code build 'stage'....
@twasink
twasink / PublicSubnets.yaml
Created January 15, 2019 12:18
Example CloudFormation stack building two public subnets.
---
AWSTemplateFormatVersion: '2010-09-09'
Description:
The Public Subnet, and associated routing information
# Metadata: # no metadata
Parameters:
Environment:
Type: String
@twasink
twasink / Globals.yaml
Created January 15, 2019 12:14
Baby's First CloudFormation Stack
---
AWSTemplateFormatVersion: '2010-09-09'
Description:
Global configuration that could be used by multiple related stacks
# Metadata: # no metadata
Parameters:
Environment:
Type: String