Skip to content

Instantly share code, notes, and snippets.

View gfargo's full-sized avatar
🥫
Revolutionizing Food Regulation with Okayd

Griffen Fargo gfargo

🥫
Revolutionizing Food Regulation with Okayd
View GitHub Profile
@5t3ph
5t3ph / gatsby-useLocation-hook-change-theme.js
Last active November 28, 2022 13:16
In Gatsby, leverage Reach Router's useLocation hook along with the query-string package to change user's selected theme, or expand to any values you need from the URL parameters, available on `location.search` from the useLocation hook.
import * as React from 'react';
import { useLocation } from '@reach/router';
import queryString from 'query-string';
const getSelectedTheme = (query) => {
const fallback = 'light';
if (query) {
const queriedTheme = queryString.parse(query);
@thatdevgirl
thatdevgirl / simple-autocomplete.js
Created November 29, 2018 15:29
Simple Autocomplete component for WP Gutenberg
/**
* A very simple autocomplete component
*
* This is to replace the OOTB Gutenberg Autocomplete component because it is
* currently broken as of v4.5.1.
*
* See Github issue: https://github.com/WordPress/gutenberg/issues/10542
*
* Note: The options array should be an array of objects containing labels and values; i.e.:
* [
@mihdan
mihdan / is_gutenberg_active.php
Created November 11, 2018 19:34 — forked from kagg-design/is_gutenberg_active.php
Function to check if Gutenberg is active.
/**
* Check if Gutenberg is active.
* Must be used not earlier than plugins_loaded action fired.
*
* @return bool
*/
private function is_gutenberg_active() {
$gutenberg = false;
$block_editor = false;
@chrislopresto
chrislopresto / component.tsx
Created September 10, 2018 20:12
styled-components v4 + createGlobalStyle + TypeScript
import * as React from 'react';
import { theme } from './theme';
import { ThemeProvider, createGlobalStyle } from './styled-components';
const GlobalStyle = createGlobalStyle`
body {
font-family: Times New Roman;
}
`;
@joeytwiddle
joeytwiddle / async-await-forEach-alternatives.md
Last active May 2, 2024 19:03
Do not use forEach with async-await

Do not use forEach with async-await

TLDR: Use for...of instead of forEach() in asynchronous code.

For legacy browsers, use for...i or [].reduce()

To execute the promises in parallel, use Promise.all([].map(...))

The problem

@SKempin
SKempin / Git Subtree basics.md
Last active May 6, 2024 14:55
Git Subtree basics

Git Subtree Basics

If you hate git submodule, then you may want to give git subtree a try.

Background

When you want to use a subtree, you add the subtree to an existing repository where the subtree is a reference to another repository url and branch/tag. This add command adds all the code and files into the main repository locally; it's not just a reference to a remote repo.

When you stage and commit files for the main repo, it will add all of the remote files in the same operation. The subtree checkout will pull all the files in one pass, so there is no need to try and connect to another repo to get the portion of subtree files, because they were already included in the main repo.

Adding a subtree

Let's say you already have a git repository with at least one commit. You can add another repository into this respository like this:

@jwilson8767
jwilson8767 / es6-element-ready.js
Last active April 22, 2024 20:28
Wait for an element to exist. ES6, Promise, MutationObserver
// MIT Licensed
// Author: jwilson8767
/**
* Waits for an element satisfying selector to exist, then resolves promise with the element.
* Useful for resolving race conditions.
*
* @param selector
* @returns {Promise}
*/
@kjbenk
kjbenk / clone-posts.php
Last active June 27, 2017 16:10
WordPress Post Cloning
<?php
/**
* This file handles the cloning of any post type.
*/
class Clone_Posts {
/**
* Instances of child classes.
*
@shashankmehta
shashankmehta / setup.md
Last active January 7, 2024 11:57
Setup PHP and Composer on OSX via Brew

First install Brew on your MAC

  • Setup Brew: ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • brew update
  • brew tap homebrew/dupes
  • brew tap homebrew/php
  • Install PHP 7.0.+ brew install php70
  • Install mcrypt: brew install mcrypt php70-mcrypt
  • Finally, install composer: brew install composer
@duroe5698
duroe5698 / add-custom-menu-item-and-endpoint-to-woocommerce-my-account-page.php
Last active July 8, 2023 18:05
Add custom menu item and endpoint to WooCommerce my-account page
/* Add custom menu item and endpoint to WooCommerce My-Account page */
function my_custom_endpoints() {
add_rewrite_endpoint( 'refunds-returns', EP_ROOT | EP_PAGES );
}
add_action( 'init', 'my_custom_endpoints' );
function my_custom_query_vars( $vars ) {
$vars[] = 'refunds-returns';