Skip to content

Instantly share code, notes, and snippets.

View chaance's full-sized avatar
🏄‍♂️
Out there

Chance Strickland chaance

🏄‍♂️
Out there
View GitHub Profile
@chaance
chaance / wp-get-primary-tax-term.php
Last active September 11, 2020 08:13
Get the Yoast SEO primary term for a given taxonomy.
<?php
/**
* Get primary taxonomy term (YoastSEO).
*
* @param mixed $taxonomy Taxonomy to check for.
* @param boolean $term_as_obj Whether to return an object or the term name.
* @param int $post_id Post ID.
* @return mixed The primary term.
*/
function xx_get_primary_tax_term( $taxonomy = 'category', $term_as_obj = true, $post_id = 0 ) {
@chaance
chaance / wp-new-admin.sql
Created July 16, 2018 22:56
Add a new WP admin user via SQL.
INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`, `user_status`)
VALUES ('chance', MD5('Password123'), 'Chance Strickland', '[email protected]', '0');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_capabilities', 'a:1:{s:13:"administrator";s:1:"1";}');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`)
VALUES (NULL, (Select max(id) FROM wp_users), 'wp_user_level', '10');
@chaance
chaance / truncate-string.php
Last active July 24, 2018 01:42
Truncate a string to a maximum number of characters to the nearest complete word.
<?php
/**
* Truncate a string to a maximum number of characters to the nearest complete word.
*
* @param string $string String to truncate.
* @param int $max_char_width Maximum number of characters.
* @param string $append New string to append at the end of the truncated string.
* @return string Truncated string.
*/
function truncate_string( $string = '', $max_char_width = 200, $append = '' ) {
@chaance
chaance / util.js
Last active March 10, 2019 19:25
Random collection of utility functions. Because we could all use fewer dependencies.
// Camel case a thing!
export const camelCase = str => `${str.charAt( 0 ).toLowerCase()}${str.replace( /[\W_]/g, '|' ).split( '|' )
.map( part => `${part.charAt( 0 ).toUpperCase()}${part.slice( 1 )}` )
.join( '' )
.slice( 1 )}`;
// Debounce a thing!
export const debounce = ( func, wait, immediate ) => {
let timeout;
return function() {
@chaance
chaance / menu.js
Created September 12, 2018 14:24
Recursive menu component (React + Next.js)
import React, { Component } from 'react';
import Link from 'next/link';
import { uniqueId } from 'lodash';
import PropTypes from 'prop-types';
class Menu extends Component {
renderSubMenu = (children) => {
if (children && children.length > 0) {
return (
<ul className="menu__submenu">{this.renderMenuItems(children)}</ul>
@chaance
chaance / semantic-commit-messages.md
Last active June 29, 2022 13:58 — forked from joshbuchea/semantic-commit-messages.md
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@chaance
chaance / _deprecated.js
Last active May 24, 2019 05:37
WordPress editor block example with deprecated versions
/**
* Each version gets a directory where I copy over all of the old block files,
* then export them from here for use in your main block file.
*/
export { default as v1 } from './v1';
export { default as v1_01 } from './v1_01';
@chaance
chaance / hooks.js
Last active May 29, 2019 23:39
Some handy hooks for React
import React from 'react';
import flattenInput from './utils/flattenInput';
/**
* Store a component's previous value in a ref for use after the value changes.
*
* const prevProps = usePrevious(props);
* const { children: prevChildren } = usePrevious(props) || {};
* const prevState = usePrevious(state);
*/
@chaance
chaance / SignUpForm.tsx
Created May 31, 2019 23:05
React hook for breezy Firebase authentication. Uses Formik for forms and Yup for field validation.
import React from 'react';
import {
Formik,
FormikProps,
Form,
Field,
FieldProps,
ErrorMessage,
} from 'formik';
import * as Yup from 'yup';
@chaance
chaance / Example.jsx
Last active June 21, 2019 04:26
React Audio player concept API
export function Example({ audioFile, ...props }) {
return (
<div>
{/* basic auidio player with normal HTML5 controls */}
<RePlays src={audioFile} {...props} />
{/* basic auidio player; pick and choose your controls */}
<RePlays src={audioFile}>
<Scrubber />