Skip to content

Instantly share code, notes, and snippets.

View davevanfleet's full-sized avatar

Dave Van Fleet davevanfleet

View GitHub Profile
@davevanfleet
davevanfleet / createSubscription.py
Created February 10, 2021 15:36
Code snippet of flask app - Create subscription view function
# Endpoint for associating sucessfully created Stripe subscription
# with the Adult document. Needs body with paymentMethodId (from
# Stripe in frontend), priceId (from frontend, matches the priceId
# for selected option in Stripe), and childId (probably will be changed
# to create child here?)
@stripe_blueprint.route('/create_subscription', methods=['POST'])
def createSubscription():
body = request.get_json()
email = body["email"]
receives_emails = body["receivesEmails"]
@davevanfleet
davevanfleet / fetchBackExercises.js
Last active April 18, 2022 02:48
fetchBackExercises.js
const fetchBackExercises = async () => {
const data = await axios.get('/exercises', {params: {muscleGroup: 'back'}});
return data;
}
const onError = (error) => {
console.error(error);
}
const { data, isLoading } = useQuery(
const ExerciseList = () => {
const fetchBackExercises = async () => {
const data = await axios.get('/exercises', {params: {muscleGroup: 'back'}});
return data;
}
const onError = (error) => {
console.error(error);
}
const { data = [], isLoading } = useQuery(
['exercises', 'back'],
const useExercises = (muscleGroup) => {
const fetchExercises = async () => {
const data = await axios.get('/exercises', {params: {muscleGroup}});
return data;
}
const onError = (error) => {
console.error(error);
}
const { data, isLoading } = useQuery(
['exercises', muscleGroup],
import axios from 'axios';
import { useQuery } from 'react-query';
const query = async ({queryKey}) => {
const [_, id] = queryKey;
const data = await axios.get(`/teams/${id}`);
return data;
}
const useTeam = (id) => {
import axios from 'axios';
import { useQuery } from 'react-query';
const useTeam = (id) => {
const query = async () => {
const data = await axios.get(`/teams/${id}`);
return data;
}
const { data, isLoading } = useQuery(['team', id], query);
import axios from 'axios';
import { useQuery } from 'react-query';
const useTeam = (id) => {
const getTeam = async () => {
const data = await axios.get(`/teams/${id}`);
return data;
}
const { data, isLoading } = useQuery(['team', id], getTeam);
const sumOfTwoNumbers = (arr, target) => {
// sort the array in asc order so we can use a sliding window technique to find sum
arr.sort((a, b) => a - b)
// use two pointers to implement a sliding window technique on sorted array
// if we never equal the target sum and the pointer cross, there is no suitable pair
let leftPointer = 0;
let rightPointer = arr.length - 1;
const sumLessThanTarget = () => arr[leftPointer] + arr[rightPointer] < target
import { useMutation, useQuery } from 'react-query';
import React from 'react';
import axios from 'axios';
const NotificationsDrawer = () => {
const {notifications, markAsRead } = useNotifications()
return (
<Drawer>
{notifications.map(notifcation => (
<NotificationCard notification={notification} markAsRead={markAsRead} />
import React, { createContext, useContext, useEffect, useState } from 'react';
import { useQuery } from 'react-query';
const TeamContext = createContext({
isLoading: false,
team: undefined,
setTeam: undefined,
allTeams: [],
});