Skip to content

Instantly share code, notes, and snippets.

View jinsley8's full-sized avatar

Jon Insley jinsley8

View GitHub Profile
@jinsley8
jinsley8 / product-loop.php
Last active February 3, 2018 22:29
product loop
/**
* Callback function of the shortcode.
*/
function ot_brand_products_cb($atts, $content){
/**
* Setting variable value none.
*/
$content = null;
@jinsley8
jinsley8 / Remote Image Slider
Created March 6, 2021 03:24 — forked from luvies/ Remote Image Slider
A JavaScript-accessible-only image slider that will slide to the next given image (after it has loaded), rather than a predetermined set. After sliding to this new image, the old one is removed, allowing you to slide any amount of images you want. You can also slide an image out or in by not providing an image location. Requires jQuery.
<!DOCTYPE html>
<!--
HTML Examples
-->
<html>
<head>
<link rel="stylesheet" href="https://rawgit.com/Gorea235/4844ce9e603d34c82b2d1253b1a71799/raw/remote-image-slider.css">
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
@jinsley8
jinsley8 / google-analytics.php
Created February 13, 2022 17:51
Enqueue Google Analytics 4 script without tracking Admin
/**
* Enqueue Google Analytics 4 script
*
*/
/* Add Google Analytics 4 Site Tag as close to
the opening <head> tag as possible
=====================================================*/
define("GA4","G-XXXXXX", false); // Replace GA4 ID
@jinsley8
jinsley8 / google-tag-manager.php
Created February 13, 2022 17:53
Enqueue Google Tag Manager script without tracking Admin
/**
* Enqueue Google Tag Manager script
*
*/
/* Add Google Tag Manager javascript code as close to
the opening <head> tag as possible
=====================================================*/
define("GTM_TAG","GTM-XXXXXX", false); // Replace with GTM tracking ID
@jinsley8
jinsley8 / useAxios.ts
Created November 29, 2022 22:16
A hook that uses axios to fetch data
import axios, { AxiosRequestConfig } from 'axios';
import { useEffect, useState } from 'react';
axios.defaults.baseURL = `${process.env.NEXT_PUBLIC_SITE_URL}/api/${process.env.NEXT_PUBLIC_API_VERSION}`;
export const useAxiosFetch = (params: AxiosRequestConfig<any>) => {
const [data, setData] = useState<any>(null);
const [error, setError] = useState<any>(null);
const [loading, setLoading] = useState<boolean>(true);
@jinsley8
jinsley8 / useDebounce.ts
Created November 29, 2022 22:18
A hook to debounce input data
import { useEffect, useState } from 'react';
export default function useDebounce<T>(value: T, delay: number): T {
// State and setters for debounced value
const [debouncedValue, setDebouncedValue] = useState<T>(value);
useEffect(
() => {
// Update debounced value after delay
const handler = setTimeout(() => {
@jinsley8
jinsley8 / useFetch.ts
Created November 29, 2022 22:18
A hook that uses fetch to fetch data
enum Method {
GET = 'GET',
POST = 'POST',
PUT = 'PUT',
PATCH = 'PATCH',
DELETE = 'DELETE',
}
const useFetch = (endpoint: string, apiKey?: object) => {
const defaultHeader = {
@jinsley8
jinsley8 / useIntersectionObserver.ts
Created November 29, 2022 22:20
A hook to observe when the uses has scrolled to on page
import React, { useEffect } from 'react';
interface IntersectionObserverProps {
root?: React.RefObject<Element | null>;
target: React.MutableRefObject<HTMLElement | null>;
onIntersect: () => void;
threshold?: number | number[];
rootMargin?: string;
enabled?: boolean;
}
@jinsley8
jinsley8 / isMetamaskInstalled.ts
Last active January 10, 2023 05:36
Check if MetaMask is installed on the browser in React
import { useEffect, useState } from 'react';
const [isMetamaskInstalled, setIsMetamaskInstalled] = useState<boolean>(false);
// Check if Metamask wallet is installed and window.ethereum exists
useEffect(() => {
if (typeof (window as any)?.ethereum !== 'undefined' && (window as any)?.ethereum?.isMetaMask) {
setIsMetamaskInstalled(true);
} else {
setIsMetamaskInstalled(false);
@jinsley8
jinsley8 / zod-parse.ts
Last active September 19, 2023 20:53
Zod Parsing Errors
import { ZodTypeAny } from 'zod';
/*
* .safeParse
*/
interface ZodResponseSuccess<T> {
success: true;
data: T;
}