Skip to content

Instantly share code, notes, and snippets.

@GarrettWeinberg
GarrettWeinberg / facetwp.php
Created January 14, 2023 16:52
FacetWP Sort to Bootstrap 5 dropdown
<?php
namespace App;
add_filter('facetwp_facets', function ($facets) {
// Register Sort Facet
$facets[] = array(
"name" => "sort",
"label" => "Sort",
"type" => "sort",
"default_label" => "Sort by",
@GarrettWeinberg
GarrettWeinberg / verifyVideoUrl.js
Created February 9, 2022 02:20
Verify youtube and vimeo urls and return correct url
export const verifyVideoLinks = async (url) => {
const YOUTUBE = process.env.REACT_APP_YOUTUBE_API;
url.match(
/(http|https?:\/\/)(player.|www.)?(vimeo\.com|youtu(be\.com|\.be|be\.googleapis\.com))\/(video\/|embed\/|watch\?v=|v\/)?([A-Za-z0-9._%-]*)(&\S+)?/
);
const id = RegExp.$6;
console.log("id", id);
let embed = null;
let verified = false;
let video;
@GarrettWeinberg
GarrettWeinberg / mongo.js
Last active April 4, 2022 18:03
Mongo shell command to add new fields to collection
// shell
db.casestudies.find().forEach(function (data) {db.casestudies.update({_id: data._id}, {$set: {links: [],documents: {},}})});
// pretty
db.casestudies.find().forEach(function (data) {
db.casestudies.update({
_id: data._id
}, {
$set: {
links: [],
{
"env": {
"browser": true, // Browser global variables like `window` etc.
"commonjs": true, // CommonJS global variables and CommonJS scoping.Allows require, exports and module.
"es6": true, // Enable all ECMAScript 6 features except for modules.
"jest": true, // Jest global variables like `it` etc.
"node": true // Defines things like process.env when generating through node
},
"extends": [
"plugin:react/recommended",
@GarrettWeinberg
GarrettWeinberg / cards-equal-height.js
Last active April 7, 2021 15:27
Make All Cards Equal Height
// cards same height
let cards = $('.card'), //get all cards
heights = [], //height values array
tallest; //tallest card
function normalizeHeights() {
cards.each(function() {
heights.push($(this).height());
});
tallest = Math.max.apply(null, heights);
// Set JS for jsonp callback
let jsonpID = 0;
function jsonp(url, timeout = 7500) {
const head = document.querySelector('head');
// set unique identifier for function
jsonpID = Math.round(Math.random() * 1000000000);
@GarrettWeinberg
GarrettWeinberg / index.js
Last active March 6, 2020 14:22
latest posts block
import { registerBlockType } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
import { InspectorControls } from "@wordpress/block-editor";
import { PanelBody, SelectControl } from "@wordpress/components";
registerBlockType( 'create-block/better-latest-posts', {
title: __( 'Better Latest Posts', 'create-block' ),
description: __(
'Example block written with ESNext standard and JSX support – build step required.',
backend:
name: git-gateway
branch: master # Branch to update (optional; defaults to master)
media_folder: "src/images" # Media files will be stored in the repo under static/images/uploads
collections:
- name: "pages"
label: "Page"
folder: "src/markdown-pages"
/**
* BLOCK: Blurb Block
*
* Registering a basic block with Gutenberg.
* Simple block, renders and saves the same content without any interactivity.
*/
// Import CSS.
import './editor.scss';
import './style.scss';