Skip to content

Instantly share code, notes, and snippets.

View dgwyer's full-sized avatar
🏠
Working from home

David Gwyer dgwyer

🏠
Working from home
View GitHub Profile
#!/bin/bash
# Number of posts to create
posts=100
# Paragraphs
p=2
# Create new posts and pages with random Lorem ipsum content inside paragraph blocks
curl -N http://loripsum.net/api/$p | sed '/^$/d' | sed 's/^/<\!-- wp:paragraph -->/' | sed 's/$/<\!-- \/wp:paragraph -->/' | wp post generate --count=$posts --post_content
#!/bin/bash
# Delete all posts for specified posts types
wp post delete $(wp post list --post_type='post,page,product,attachment' --format=ids) --force
#!/bin/bash
# Start the timer
start_time=$(date +%s)
# Vars
import_images=12
# 1. IMPORT MEDIA
import fs from 'fs';
import needle from 'needle';
import cryptojs from 'crypto-js';
import config from '../../../../caller/deploy.config.js';
export function deployZip() {
// Base 64 URL encode.
const base64_url_encode = function (str) {
str = Buffer.from(str).toString('base64');
str = str.replace(/=/g, '');
@dgwyer
dgwyer / what-forces-layout.md
Created October 19, 2022 14:00 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
<?php
/**
* Plugin Name: Post Meta Registration Test
* Version: 0.1.0
* Text Domain: post-meta-registration-test
*/
function register_post_meta_1() {
register_post_meta( 'post', 'test_post_data1', array(
'show_in_rest' => true,
<?php
$source_file = 'readme.txt';
$target_file_pro = 'tmp/changelog-pro.md';
$target_file_free = 'tmp/changelog-free.md';
$handle = fopen($source_file, 'r');
$changelog_pro = [];
<?php
function add_gb_script() {
wp_enqueue_script(
'gb-script',
get_stylesheet_directory_uri() . '/gb_script.js',
array( 'wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', 'wp-api' )
);
}
add_action( 'enqueue_block_editor_assets', 'add_gb_script' );
@dgwyer
dgwyer / boxes.css
Last active May 12, 2018 08:29
Three boxes from Minn live demo
.featured-box-row {
display: table;
border-collapse: separate;
border-spacing: 15px 10px
}
.featured-box-row.featured-box-no-margin {
margin: 0 -15px
}
@dgwyer
dgwyer / outline1.css
Last active December 31, 2018 23:18
Useful outline styles to help debug CSS without affecting layout.
* > * { outline: 1px rgba(255, 0, 0, 1) solid !important;}
* > * > * { outline: 1px rgba(255, 0, 0, 1) dashed !important;}
* > * > * > * { outline: 1px rgba(255, 0, 0, 1) dotted !important;}
* > * > * > * > * { outline: 1px rgba(255, 0, 0, 0.6) solid !important;}
* > * > * > * > * > * { outline: 1px rgba(255, 0, 0, 0.3) solid !important;}