Skip to content

Instantly share code, notes, and snippets.

View coryhouse's full-sized avatar

Cory House coryhouse

View GitHub Profile
@coryhouse
coryhouse / package.json
Last active April 26, 2024 13:01
Example of calling one script from another
{
"name": "npm-scripts-example",
"version": "1.0.0",
"description": "npm scripts example",
"scripts": {
"clean": "rimraf ./dist && mkdir dist",
"prebuild": "npm run clean",
"build": "cross-env NODE_ENV=production webpack"
}
}
@coryhouse
coryhouse / useSafeState.js
Created January 23, 2020 01:35
React useSafeState hook - Only set state if mounted
import { useEffect, useRef, useState } from "react";
/**
* Provides the functionality of React.useState() with the only difference that
* it sets a state only if its parent component is still mounted, aka "safe setState".
*/
export default function useSafeState(initialState) {
const mountedRef = useRef(false);
const [state, setState] = useState(initialState);
@coryhouse
coryhouse / extensions.json
Created April 10, 2023 16:11
Put this file in .vscode to recommend extensions
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"streetsidesoftware.code-spell-checker",
"GitHub.vscode-pull-request-github",
"ms-playwright.playwright",
"pflannery.vscode-versionlens",
"ZixuanChen.vitest-explorer"
]
@coryhouse
coryhouse / package.json
Last active November 9, 2023 06:04
Example of pre and post scripts in package.json
{
"name": "npm-scripts-example",
"version": "1.0.0",
"description": "npm scripts example",
"scripts": {
"prebuild": "echo I run before the build script",
"build": "cross-env NODE_ENV=production webpack",
"postbuild": "echo I run after the build script"
}
}
@coryhouse
coryhouse / AllComponents.test.ts
Created May 25, 2022 19:02
Enforce tests exist for each component
// This file assures that a Jest test file and Cypress test file exists for each component.
import path from "path";
import fs from "fs";
function getFiles(filepath: string) {
return fs.readdirSync(filepath).filter(function (file) {
return fs.statSync(path.join(filepath, file)).isFile();
});
}
@coryhouse
coryhouse / GetUserPermissionsResponse.ts
Last active July 6, 2023 14:23
Permission response
/** Return this when the user signs in */
type GetUserPermissionsResponse = {
featurePermissions: FeaturePermission[];
projectPermissions: ProjectPermission[];
};
type FeaturePermission = {
subModuleId: number;
permissions: Permission[];
};
@coryhouse
coryhouse / useHasCamera.ts
Created May 20, 2023 19:18
useHasCamera custom hook
import { useEffect, useState } from "react";
type Cameras = {
back: boolean;
front: boolean;
};
/** Returns a device's cameras and their location */
export default function useHasCamera() {
const [cameras, setCameras] = useState<Cameras | null>(null);
@coryhouse
coryhouse / mockDataSchema.js
Last active April 15, 2023 15:09
Mock Data Schema for "Building a JavaScript Development Environment" on Pluralsight
export const schema = {
"type": "object",
"properties": {
"users": {
"type": "array",
"minItems": 3,
"maxItems": 5,
"items": {
"type": "object",
"properties": {
@coryhouse
coryhouse / webpack.config.dev.js
Last active April 15, 2023 15:08
Development Webpack config for "Building a JavaScript Development Environment" on Pluralsight
import path from 'path';
export default {
debug: true,
devtool: 'inline-source-map',
noInfo: false,
entry: [
path.resolve(__dirname, 'src/index')
],
target: 'web',
@coryhouse
coryhouse / .eslintrc.json
Last active April 15, 2023 15:08
.eslintrc.json file for "Building a JavaScript Development" Pluralsight course
{
"root": true,
"extends": [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"