Skip to content

Instantly share code, notes, and snippets.

View andyshora's full-sized avatar

Andy Shora andyshora

View GitHub Profile
import React from "react"
import styled from "styled-components"
import { makeStyles } from "@material-ui/core/styles"
import { Table, TableBody, TablePagination } from "@material-ui/core"
import { animated, interpolate, Trail } from "react-spring/renderprops"
import Stars from "../Stars"
import {
StyledTableCell,
StyledTableRow,
SortableTableHead
@andyshora
andyshora / hooks.js
Last active December 2, 2020 10:07
Debug React re-renders
function useTraceUpdate(props) {
const prev = useRef(props);
useEffect(() => {
const changedProps = Object.entries(props).reduce((ps, [k, v]) => {
if (prev.current[k] !== v) {
ps[k] = [prev.current[k], v];
}
return ps;
}, {});
if (Object.keys(changedProps).length > 0) {
@andyshora
andyshora / fix.md
Created July 31, 2020 15:02
"regeneratorRuntime is not defined" FIX

Error: regeneratorRuntime is not defined

When: When installing a package (packaged for modern browsers, i.e. no polyfills) and added to a project supporting older browsers.

Solution: Install regenerator-runtime package and add the following line to main entry file:

import 'regenerator-runtime/runtime'

const linearInterpolate = interpolateObject({ val: 0 }, { val: 100 })
console.log(linearInterpolate(0.25))
console.log(linearInterpolate(0.75))
const easeInterpolate = easeFn => (a, b) => {
const i = interpolateObject(a, b)
return t => i(easeFn(t))
}
const curvedInterpolate = easeInterpolate(easeQuadInOut)({ val: 0 }, { val: 100 })
console.log(curvedInterpolate(0.25))
@andyshora
andyshora / BufferGeometry.js
Created July 30, 2019 10:24
BufferGeometry with alpha custom blending
particlesGeometry.current = new THREE.BufferGeometry()
particlesGeometry.current.addAttribute('position', new THREE.Float32BufferAttribute(positions.current, 3).setDynamic( true ))
particlesGeometry.current.addAttribute('color', new THREE.Float32BufferAttribute(colorBuffer, 3).setDynamic( true ))
const loader = new THREE.TextureLoader()
const texture = loader.load(lensflare)
texture.premultiplyAlpha = false
texture.needsUpdate = true
const blendSrc = { name: 'SrcAlpha', constant: THREE.SrcAlphaFactor }
// REACT
export interface HeaderProps { initial?: number }
// initial is optional, and has a default value set
// Header is of type React.SFC (stateless functional component) (see: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/react/index.d.ts)
const Header: FunctionComponent<HeaderProps> = ({ initial = 5 }) => {}
// Event Handlers
// (see: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/6b5ceb41aafa8e41d0f99aabc910ebad5442c008/types/react/index.d.ts#L788) for types
class MyComponent extends React.Component<MyComponentProps> {
@andyshora
andyshora / AuthService.js
Last active February 20, 2019 14:42
Example managing keys, converting array buffers to strings.
import * as log from 'loglevel';
import { utils } from '@qadre/sdk-client';
import b64 from 'base64-js';
import moment from 'moment';
import { stringToBuffer } from './utils';
// Services
import { Storage } from './ConfigService';
@andyshora
andyshora / prints.md
Created September 11, 2018 12:06
Qadre Office Prints

Qadre Prints

img img img img [![img](h

@andyshora
andyshora / mylist.js
Created April 9, 2018 10:24
Qadre Technical Test - React - PUBLIC
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import _ from 'lodash';
class List extends React.Component {
render() {
const {
name,
data