Skip to content

Instantly share code, notes, and snippets.

View adamsilverstein's full-sized avatar
💭
Working remotely, as usual

Adam Silverstein adamsilverstein

💭
Working remotely, as usual
View GitHub Profile
CREATE TEMP FUNCTION getFeatures(payload STRING)
RETURNS STRING
LANGUAGE js
AS '''
try {
var $ = JSON.parse(payload);
var almanac = JSON.parse($._almanac);
var generators = almanac['meta-nodes'].nodes.find(node => node.name == 'generator' && node.content.startsWith("Elementor"));
if ( generators.length == 0 ) {
return "";
CREATE TEMP FUNCTION IS_GOOD(good FLOAT64, needs_improvement FLOAT64, poor FLOAT64)
RETURNS BOOL
AS (
good / (good + needs_improvement + poor) >= 0.75
);
CREATE TEMP FUNCTION IS_NON_ZERO(good FLOAT64, needs_improvement FLOAT64, poor FLOAT64)
RETURNS BOOL
AS (
good + needs_improvement + poor > 0
class Custom_REST_Users_Controller extends WP_REST_Users_Controller {
/**
* Registers the routes for the controller.
*/
public function register_routes() {
parent::register_routes();
add_filter( 'rest_user_query', array( $this, 'filter_user_query_by_meta_fields' ), 10, 2 );
}
#standardSQL
# Breakdown of scripts using Async, Defer, Module or NoModule attributes. Also breakdown of inline vs external scripts
CREATE TEMPORARY FUNCTION getScripts(payload STRING)
RETURNS
STRUCT<
total INT64,
inline INT64,
src INT64,
async INT64,
# Breakdown of scripts using Async, Defer, Module or NoModule attributes. Also breakdown of inline vs external scripts
CREATE TEMPORARY FUNCTION getScripts(payload STRING)
RETURNS
STRUCT<
total INT64,
inline INT64,
src INT64,
async INT64,
defer INT64,
async_and_defer INT64,
@adamsilverstein
adamsilverstein / drupal-cwv-by-version.sql
Created October 26, 2022 17:04
Drupal Core Web Vitals by Version
CREATE TEMP FUNCTION IS_GOOD(good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS (
good / (good + needs_improvement + poor) >= 0.75
);
CREATE TEMP FUNCTION IS_NON_ZERO(good FLOAT64, needs_improvement FLOAT64, poor FLOAT64) RETURNS BOOL AS (
good + needs_improvement + poor > 0
);
#standardSQL
# Breakdown of scripts using Async, Defer, Module or NoModule attributes. Also breakdown of inline vs external scripts
CREATE TEMPORARY FUNCTION getScripts(payload STRING)
RETURNS
STRUCT<
total INT64,
inline INT64,
src INT64,
async INT64,
defer INT64,
WITH wordpress AS (
SELECT DISTINCT
url
FROM
`httparchive.technologies.2022_09_01_*`
WHERE
app = 'WordPress'
)
SELECT
@adamsilverstein
adamsilverstein / output-webp.php
Last active September 30, 2022 19:59
Output WebP mini plugin
<?php
/**
* Outout WebP sub size images.
*
* @wordpress-plugin
* Plugin Name: WebP-only.
* Description: Output WebP sub size images.
* Plugin URI:
* Version: 1.0.0
* Author: Adam Silverstein, Google
@adamsilverstein
adamsilverstein / only-webp.php
Last active December 2, 2022 19:47
only webp with performance plugin
<?php
/**
* Output only WebP sub size images.
*
* @wordpress-plugin
* Plugin Name: WebP-only.
* Description: Output only WebP sub size images.
* Plugin URI:
* Version: 1.0.0
* Author: Adam Silverstein, Google