Skip to content

Instantly share code, notes, and snippets.

View codfish's full-sized avatar

Chris O'Donnell codfish

View GitHub Profile
@codfish
codfish / Module.jsx
Last active April 30, 2021 21:17
React Module component with context
import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import styles from './Module.style';
import { Provider } from '../context/module';
const Module = ({ expandable, closed, children, className: classNameProp, ...other }) => {
const className = clsx(styles.root, classNameProp);
return (
@codfish
codfish / rsaa-cache-middleware.js
Last active April 20, 2020 20:40
Dynamic RSAA (redux-api-middleware) cache middleware. Must come before rssa in middleware order.
import { RSAA } from 'redux-api-middleware';
import get from 'lodash/get';
/**
* Intercept redux api middleware actions and bailout of api resource requests
* if the resource is already in the store.
*
* NOTE: State always gets updated on non-GET requests, essentially updating our "cache"
*
* Examples of resource routes that we want to cache:
@codfish
codfish / roman-to-decimal.js
Created April 13, 2020 14:45
Convert decimal number to Roman numeral
const NUMERALS = {
I: 1,
V: 5,
X: 10,
L: 50,
C: 100,
D: 500,
M: 1000,
IV: 4,
IX: 9,
@codfish
codfish / new_mac.sh
Last active June 25, 2022 13:53
Setup new Mac
xcode-select --install
ssh-keygen
cat ~/.ssh/id_rsa.pub | pbcopy
# -> add ssh key to github
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/codfish/dotfiles/main/install.sh) --with-apps"
# -> open dropbox and log in
sh ~/Dropbox/configfiles/bin/setup
@codfish
codfish / meta-service.js
Created September 16, 2019 12:39
AngularJS v1 Meta Service
// ***********************************************************************************
// meta-service.js
'use strict';
/**
* Meta Service
*
* The Meta Service allows you to abstract a lot of business logic
* that goes into setting meta & link tags for your templates.
@codfish
codfish / now-headers.json
Last active November 13, 2020 16:19
Cache control headers for static assets with Now. http://r.codfi.sh/Ukim4l
{
"version": 2,
"name": "codfish.io",
"alias": "codfish.io",
"builds": [{ "src": "package.json", "use": "@now/static-build" }],
"routes": [
{
"src": ".*\\.(js|css|jpg|jpeg|gif|png|svg|txt|ttf|woff2|webmanifest)$",
"headers": {
"Cache-Control": "public, max-age=157680000, s-maxage=157680000"
@codfish
codfish / #linting.md
Last active May 6, 2024 18:12
Prettier + ESLint + Husky + lint-staged + commitlint

My personal & professional linting setup. Run's Prettier as an ESLint rule via their ESLint plugin. Dynamic support for react or non-react applications depending on your project dependencies. Dynamic inclusion of Kent C Dodds' ESLint Jest config depending on your project dependencies.

Convenient opt-in configs for projects using Docker or Ethereum to avoid common false positives.

To understand more, see https://github.com/codfish/eslint-config-codfish.

To avoid having to manually setup everything and add all configuration/boilerplate code to your project, use cod-scripts instead. It was forked from kcd-scripts and ultimately inspired by react-scripts.

Why

@codfish
codfish / docblocks-spec.md
Last active November 14, 2023 16:46
Documenting your code

Documenting Your Code

This is a detailed spec on how developers should be documenting their code. While inline code comments are very important, this specification will be focusing on docblock structure.

Docblocks are required for all class methods & properties/attributes. The reason we have this spec, and the reason that actual language standards exist for docblocks, is so that generators will know how to parse your code & render consumable html documentation.

For this reason, documentation standards follow the existing spec's that are currently community standards at the time of writing, and we should be following them.

@codfish
codfish / Ethereum event fixtures for js.md
Last active January 15, 2019 13:44
Ethereum event fixtures for js.

To install a relatively recent version of Faker you'll need to install from a commit. The maintainer is still active and merging new features, but does not cut new releases.

npm install --save-dev faker@Marak/faker.js#<commit-sha>

I.e. npm install --save-dev faker@Marak/faker.js#d3ce6f1 (latest commit at the time of writing).

@codfish
codfish / error-handling.js
Last active January 4, 2019 18:03
Default express api error handling middleware.
/**
* Handle application errors.
*
* NOTE: 500 status code is returned by default.
*
* To properly leverage this middleware, rather than return responses in your routes,
* simply set a response status in the route and then pass the error object to `next`.
* This middleware will catch that error and handle it in a consistent way across
* the entire application. For example:
*