Skip to content

Instantly share code, notes, and snippets.

View shane-js's full-sized avatar

Shane shane-js

  • Florida, USA
View GitHub Profile
@shane-js
shane-js / expressJsonValidatorMiddlewareWithBetterAjvErrors.ts
Last active July 10, 2024 21:04
Quick & dirty modification of express-json-validator-middleware to support using @apideck/better-ajv-errors on errors output
// Adapted from 'express-json-validator-middleware' package https://github.com/simonplend/express-json-validator-middleware
// Modified to be able to use @apideck/better-ajv-errors package
// Relevant Github Issue: https://github.com/simonplend/express-json-validator-middleware/issues/123
import {
betterAjvErrors,
ValidationError as BetterAjvErrorObject,
} from "@apideck/better-ajv-errors";
import { Request } from "express";
import { RequestHandler } from "express-serve-static-core";
import { JSONSchema6 } from "json-schema";
@shane-js
shane-js / ObjectionJsTransactionsInJasmine.js
Created November 19, 2020 15:24
Jasmine Tests: Using Transactions with ObjectionJS
it("can use a transaction for the current test and roll it back after", async function () {
const transactionForThisTest = await MyObjectionJsModel.startTransaction();
spyOn(MyObjectionJsModel, "query")
.withArgs()
.and.callFake(() => MyObjectionJsModel.query(transactionForThisTest) as any)
.withArgs(transactionForThisTest)
.and.callThrough();
const result = await someMethodThatChangesTheDatabaseState();
@shane-js
shane-js / ExtendedObjectionModel.js
Created June 2, 2020 03:14
ObjectionJS Postgres SQL Save JS Dates with JsonSchema "date-time" String Validation
import { Model } from "objection";
import _ from "lodash";
export class ExtendedObjectionModel extends Model {
// Use this instead of Objection's Model when making your models to fix the "is not a string" error you get when saving a JS date object to a psql datetime (timestamp) column.
// This is a WIP you may need to make some modifications.
// The main idea is to check those fields which we said should be "date-time" formatted strings in their model's jsonSchema before validation runs. If the field is a JS date, convert it to a string now before running real validation.
$beforeValidate(jsonSchema, json, opt) {
_.each(jsonSchema.properties, (schema, propertyName) => {
if (
@shane-js
shane-js / Build Commands
Created April 30, 2020 21:13
S3 Static App Build Commands - Re: Medium Story - Automated Deployment of AWS S3 Static Web App using CloudFormation / SAM and CodePipeline
version: 0.2
#env:
#variables:
# key: "value"
# key: "value"
#parameter-store:
# key: "value"
# key: "value"
#secrets-manager:
@shane-js
shane-js / buildspec.yml
Created April 30, 2020 20:52
Main Build's buildspec.yml File - Re: Medium Story - Automated Deployment of AWS S3 Static Web App using CloudFormation / SAM and CodePipeline
version: 0.2
phases:
install:
runtime-versions:
python: 3.8
build:
commands:
- pip install pipenv --user
- pipenv run python -m pip install pip==19.2.3 # helped resolve a bug I encountered in deploying by downgrading - can try leaving to most up to date again in the future
- pipenv install awscli aws-sam-cli
@shane-js
shane-js / CSharpSqlIdentifierParser.cs
Last active September 28, 2017 04:37
C# Sql Identifier Parser
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
namespace CSharpSqlIdentifierParser
{
public class CSharpSqlIdentifierParserClass
{
// Parses funky sql identifiers as strings back as their individual components which hopefully makes them easier to read
// Examples: