Skip to content

Instantly share code, notes, and snippets.

View kellenmace's full-sized avatar

Kellen Mace kellenmace

View GitHub Profile
import { formatDistance, parseISO } from 'date-fns';
// Example string date
const dateString: string = "2023-05-23";
// Parse the string date into a JavaScript Date object
const date: Date = parseISO(dateString);
// Get the current date
const currentDate: Date = new Date();
@kellenmace
kellenmace / wpgraphql-prev-next-pagination.php
Last active December 6, 2023 02:02
Example of a previous/next WPGraphQL pagination plugin
<?php
/**
* Plugin Name: WPGraphQL Previous / Next Pagination
* Description: Enables Previous / Next Pagination via WPGraphQL
* Version: 0.1.0
* Author: Kellen Mace
* Author URI: https://kellenmace.com/
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
@kellenmace
kellenmace / youtube-video-categories-may-2023.txt
Created May 23, 2023 04:34
Categories that content creators can apply to their YouTube videos as of May, 2023
Autos & Vehicles
Comedy
Education
Entertainment
Film & Animation
Gaming
Howto & Style
Music
News & Politics
Nonprofits & Activism
<?php
/**
* Plugin Name: Pagination Fields
* Description: Adds next & prev post data to WPGraphQL schema
* Version: 0.1.0
* Author: Kellen Mace
* Author URI: https://kellenmace.com/
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
import { supabase } from '$lib/supabaseClient';
import type { AuthUser } from '@supabase/supabase-js';
import { writable } from 'svelte/store';
import type { Profile } from '../types/supabase';
interface User extends Omit<AuthUser, 'email'>, Profile {};
export const user = writable<User | undefined>(undefined);
supabase.auth.onAuthStateChange(async (event, session) => {
@kellenmace
kellenmace / faust-post-filtering-example.tsx
Created November 17, 2021 18:32
Faust.js Post Filtering Example
import { useState, useMemo } from "react";
import { getNextStaticProps } from '@faustjs/next';
import { GetStaticPropsContext } from 'next';
import { client } from '../../client';
import debounce from "just-debounce-it";
export default function Blog() {
const { usePosts, useQuery } = client;
const [selectedCategory, setSelectedCategory] = useState(undefined);
const [selectedAuthor, setSelectedAuthor] = useState(undefined);
@kellenmace
kellenmace / wpgraphql-user-meta-fields.php
Last active October 19, 2021 14:37
WPGraphQL User Meta Example
<?php
namespace MyCoolApp;
use WPGraphQL\Model\User;
class UserFields {
public function register_hooks() {
add_action( 'graphql_register_types', [ $this, 'register_fields' ] );
}
<?php
/**
* Set Organization posts to 'private' for unauthenticated users.
*
* @param boolean $is_private Whether the model is private
* @param string $model_name Name of the model the filter is currently being executed in
* @param mixed $data The un-modeled incoming data
* @param string|null $visibility The visibility that has currently been set for the data at this point
* @param null|int $owner The user ID for the owner of this piece of data
@kellenmace
kellenmace / index.js
Last active October 2, 2023 16:20
Get YouTube Video Transcript in JavaScript
const fetch = require("node-fetch");
const xml2js = require("xml2js");
const he = require("he");
const TRANSCRIPTION_CHAR_KEY = "transcription";
// Test
(async () => {
const videoId = "ht14hTTDklA"; // HWPR Pagination video
// const videoId = "rB9ql0L0cUQ"; // Video with manually added captions
<?php
// Get all tag url paths for sitemap.
add_action('graphql_register_types', function () {
register_graphql_field('RootQuery', 'getTagUrlPaths', [
'type' => ['list_of' => 'String'],
'args' => [
'pageNo' => [
'type' => 'Int',
'description' => __('Page number', 'text-domain'),