Skip to content

Instantly share code, notes, and snippets.

// In production, we register a service worker to serve assets from local cache.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on the "N+1" visit to a page, since previously
// cached resources are updated in the background.
// To learn more about the benefits of this model, read https://goo.gl/KwvDNy.
// This link also includes instructions on opting out of this behavior.
// store/index.js
const createStore = () => {
return new Vuex.Store({
state: {
counter: 0,
repos: []
},
actions: {
LOAD_REPOS: function({ commit }) {
axios.get('url').then((res) => {
// D1 average tempo and D1 average efficiency vary daily but this is what I have for 1/28/18
const D1AverageTempo = 68.3185185185185 // the average tempo of all Division1 teams
const D1AverageEfficiency = 104.07578347578351 // the average combined offensive and defensive efficiency of all Division1 teams
const offensiveWeight = 1.014; // Offensive weight for the home team
const defensiveWeight = 0.986; // Defensive weight for the home team
const awayOffensiveEfficiency = awayOffensiveEfficiency * defWeight;
const awayDefensiveEfficiency = awayDefensiveEfficiency * offWeight;
const statusCodes = {
'100': 'Continue',
'101': 'Switching Protocols',
'102': 'Processing',
'200': 'OK',
'201': 'Created',
'202': 'Accepted',
'203': 'Non-Authoritative Information',
'204': 'No Content',
'206': 'Partial Content',
@lsbyerley
lsbyerley / lazy-load-images.js
Last active October 24, 2020 17:37
Lazy loading images function. Use Intersection Observer API if available, if not, fallback to the method involving event listeners
document.addEventListener("DOMContentLoaded", function() {
var lazyloadImages;
if ("IntersectionObserver" in window) {
lazyloadImages = document.querySelectorAll(".lazy");
var imageObserver = new IntersectionObserver(function(entries, observer) {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
var image = entry.target;
image.src = image.dataset.src;
@lsbyerley
lsbyerley / totalPriceReduceFunction.js
Last active July 31, 2020 13:45
Calculate total of product prices in cart with reduce
console.clear();
const cart = [
{price: 12, amount: 1},
{price: 7.5, amount: 2},
{price: 8, amount: 4}
];
const total = [...cart].reduce((total, { amount, price }) => {
return (total += amount * price);
import { useState } from 'react';
import { put } from 'axios';
const useUploadFileToS3 = () => {
const [uploadProgress, setUploadProgress] = useState(0);
const [isUploading, setIsUploading] = useState(false);
const [isSuccessful, setIsSuccessful] = useState(false);
const uploadFileToS3 = (fileData, s3URL) => {
setIsUploading(true);
@lsbyerley
lsbyerley / useCurrentLocation.js
Created March 6, 2021 14:33
useLocation React Hook
import { useState, useEffect } from "react";
const useCurrentLocation = (options = {}) => {
// store location in state
const [location, setLocation] = useState();
// store error message in state
const [error, setError] = useState();
// Success handler for geolocation's `getCurrentPosition` method
const handleSuccess = (pos) => {
@lsbyerley
lsbyerley / useWatchLocation.js
Created March 7, 2021 15:35
useWatchLocation Location API Hook
import { useState, useEffect, useRef } from "react";
const useWatchLocation = (options = {}) => {
// store location in state
const [location, setLocation] = useState();
// store error message in state
const [error, setError] = useState();
// save the returned id from the geolocation's `watchPosition` to be able to cancel the watch instance
const locationWatchId = useRef(null);
const hre = require('hardhat');
const zksync = require('zksync');
const GOVERNANCE_RINKEBY = '0xC8568F373484Cd51FDc1FE3675E46D8C0dc7D246';
const NFT_CONTRACT = '0x6B1b6167B423505CCa1265Bf9E64AC6bd374Ea9e'; // deployed contract address
async function main() {
const NFTContract = await hre.ethers.getContractFactory('NFTContract');
const ethersProvider = new hre.ethers.getDefaultProvider('rinkeby');