Skip to content

Instantly share code, notes, and snippets.

View andrit's full-sized avatar

Andrew Ritter andrit

View GitHub Profile
export const scrollToTop = () => {
  const c = document.documentElement.scrollTop || document.body.scrollTop;
  if (c > 0) {
    window.requestAnimationFrame(scrollToTop);
    window.scrollTo(0, c - c / 8);
  }
};
//export default createQueue = () => { //need static
function createQueue(){
	//cache
	//Private
	const queue = [];
	//Revealing Module Pattern
	return {
		enqueue(item) {
 queue.unshift(item);
function slow(x) {

  // there can be a heavy CPU-intensive job here

  alert(`Called with ${x}`);

  return x;

}
const flattenArr = (a) =>{
	//return a reducer function
	return a.reduce(function(acc, curr) {
		//if current value is an array member, 
		Array.isArray(curr)
			//push the value of the recursed function at the currentValue index and the rest of the array through destructuring
			? acc.push(...flattenArr(curr))
			//else, push the current value into the accumulator array
 : acc.push(curr)

(from WesBos Advanced React and GraphQL course)[https://advancedreact.com/]

export default function(amount) {
  const options = {
    style: 'currency',
    currency: 'USD',
    minimumFractionDigits: 2,
  };
  // if its a whole, dollar amount, leave off the .00
 if (amount % 100 === 0) options.minimumFractionDigits = 0;
 mkdir {a,b,c}/{1,2,3}

Use as a component builder script.

If we did DDD for the interface and know what our components are, we could run a bash that spits out or component-module directory for the whole project with one Bash.

import React from 'react'
import ReactDOM from 'react-dom'

const root = document.getElementById('root');
//need second div beside app 'root'
const modalRoot = document.getElementById('modal-root')

class Modal extends React.Component {
import React from 'react';
import Transition from 'react-transition-group/Transition';

//build config file to then expose interface controls on cms and grant ability to edit all animations from one dashboard
const duration = 400;
const duration2 = 800;

const defaultStyle = {
  transition: `opacity ${duration2}ms ease-in-out, right ${duration}ms ease-in-out`,
@andrit
andrit / uppercaseWordsInSTring.md
Last active October 10, 2018 17:12
uppercase every word in a string
String.prototype.toUpperCaseAll = function () {
return this.split(" ").map( w => w.charAt(0).toUpperCase() + w.substr(1, w.length-1)).join(" ");
};
@andrit
andrit / startCRAprjBash.md
Last active October 11, 2018 20:28
cretae a CRA JS project with a bash Script

create bash script init-cra.sh with Vim

mkdir to create space for project

echo "Initializing JS project at $(pwd)" git init npm init -y create-react-app . npm i node-sass redux react-redux react-router code .