Skip to content

Instantly share code, notes, and snippets.

@lsbyerley
lsbyerley / supabaseOnSubmitForm.js
Last active August 27, 2022 01:32
Supabase Update Function on Form Submit
import Head from 'next/head';
import Layout from '@/components/Layout';
import { useForm } from 'react-hook-form';
import {
getUser,
withPageAuth,
supabaseServerClient,
} from '@supabase/auth-helpers-nextjs';
import { supabase } from '@/lib/supabaseClient';
@lsbyerley
lsbyerley / initalize-deploy.js
Created April 14, 2022 22:12
Deploy and Initialize Starknet Account
const fs = require('fs');
const starknet = require('starknet');
const { ec, defaultProvider, json, Contract } = starknet;
const starkKeyPair = ec.getKeyPair(user.privateKey);
const starkKeyPub = ec.getStarkKey(starkKeyPair);
const compiledArgentAccount = json.parse(fs.readFileSync('./utils/ArgentAccount.json').toString('ascii'));
const accountResponse = await defaultProvider.deployContract({
contract: compiledArgentAccount,
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');
@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);
@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) => {
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 / 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);
@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;
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',
// 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;