Skip to content

Instantly share code, notes, and snippets.

View iRoachie's full-sized avatar

Kyle Roach iRoachie

View GitHub Profile
@iRoachie
iRoachie / stuff.js
Created April 4, 2024 14:44
joi validation
const Joi = require('joi');
const bcrypt = require('bcrypt');
const { checkRecordsExists, insertRecord } = require('../utils/sqlSchemaFunction');
const SignUpSchema = Joi.object({
email: Joi.string().email({ minDomainSegments: 2, tlds: { allow: ['com', 'net'] } }).required(),
username: Joi.string().alphanum().min(3).max(15).required(),
password: Joi.string().min(8).required(),
});
@iRoachie
iRoachie / Kiosk.tsx
Last active September 7, 2023 20:36
Broadcast Channels
const Kiosk = () => {
const [voter, setVoter] = useState<Voter | null>(null);
useEffect(() => {
const channel = connect();
channel.onmessage = (event) => {
const qrCodePrompted = QRCodePrompted.safeParse(event.data);
const qrCodeDismissed = QRCodeDismissed.safeParse(event.data);
@iRoachie
iRoachie / backend-route.ts
Created May 9, 2023 13:23
S3 presigner and upload
import { PutObjectCommand, S3Client } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
import { createRouter } from 'next-connect';
import type { NextApiRequest, NextApiResponse } from 'next';
import { config as appConfig } from '../../../config';
import { apiHandler, hasRequiredScopes } from '../../../util/util';
const { aws } = appConfig;
@iRoachie
iRoachie / stack.ts
Created April 20, 2023 16:00
Using Provisioned Concurrency with Lambda version
import * as cdk from 'aws-cdk-lib';
import { PredefinedMetric, ScalableTarget, ServiceNamespace, TargetTrackingScalingPolicy } from 'aws-cdk-lib/aws-applicationautoscaling';
import { Role } from 'aws-cdk-lib/aws-iam';
import { Runtime, Function, Code, Version } from 'aws-cdk-lib/aws-lambda';
import { Construct } from 'constructs';
import { join } from 'path';
export class TestStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
@iRoachie
iRoachie / RenderDate.tsx
Created February 6, 2023 15:32
Simple component to show dates without server/client mismatch
import classNames from 'classnames';
import { useEffect, useState } from 'react';
interface Props {
children: React.ReactNode;
}
export const RenderDate = ({ children }: Props) => {
const [hasMounted, setHasMounted] = useState(false);
@iRoachie
iRoachie / HookFormInput.tsx
Created June 20, 2022 10:32
Hook form usage
import {
FormControl,
FormLabel,
Input,
FormErrorMessage,
FormHelperText,
} from '@chakra-ui/react';
import classNames from 'classnames';
import { useController } from 'react-hook-form';
@iRoachie
iRoachie / yup-schema.js
Last active January 26, 2022 20:19
Yup validation of comma delimited string
const schema = yup.object({
id: yup
.array()
.transform((value, originalValue, context) => {
if (context.isType(value) && value !== null) {
return value;
}
return originalValue ? String(originalValue).split(/[\s,]+/) : [];
})
@iRoachie
iRoachie / Podfile
Created September 23, 2021 06:46
M1 macs cocoapods workaround
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
platform :ios, '11.0'
target 'AwesomeProject' do
config = use_native_modules!
use_react_native!(
:path => config[:reactNativePath],
@iRoachie
iRoachie / reporting.yml
Last active June 8, 2020 15:04
Github Actions
name: Staging Deploy
on:
release:
types: [prereleased]
jobs:
lint:
runs-on: ubuntu-latest
steps:
@iRoachie
iRoachie / index.test.ts
Last active March 5, 2024 13:07
Mocking node modules using typescript
import { mocked } from 'ts-jest/utils';
import fetch, { Response } from 'node-fetch';
import { test } from './index';
jest.mock('node-fetch');
it('It works', async () => {
console.log = jest.fn();