Skip to content

Instantly share code, notes, and snippets.

View westonruter's full-sized avatar

Weston Ruter westonruter

View GitHub Profile
@westonruter
westonruter / gist:311373
Created February 22, 2010 19:21
jQuery fallback implementation of HTML5 placeholder attribute
if(!jQuery('<input PLACEHOLDER="1" />')[0].placeholder){ //Uppercase attr for IE
jQuery(':input[placeholder]').each(function(){
var $this = $(this);
if(!$this.val()){
$this.val($this.attr('placeholder'));
$this.addClass('input-placeholder');
}
}).live('focus', function(e){
var $this = $(this);
if($this.hasClass('input-placeholder')){

Examining how Google Fonts returns different Roboto font files for various User-Agent strings. (h/t https://stackoverflow.com/a/27308229/93579)

The src URLs referenced below are what get served to the browsers when they access this font:

<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">

This is referenced as part of a Tweet. For responding, please reply on Twitter as Gist comments send no notifications.

@westonruter
westonruter / class-grouped-numbers.php
Last active February 23, 2024 01:43
Test case to demonstrate erroneous static analysis in PhpStorm
<?php declare(strict_types = 1);
final class Grouped_Numbers {
/**
* Grouped numbers.
*
* @var array<string, int[]>
*/
private $grouped_numbers;
<?php
/**
* Plugin Name: Admin PWA
* Plugin URI: https://github.com/GoogleChromeLabs/pwa-wp/issues/295
* Description: Proof of concept to turn the WordPress admin into a PWA.
* Version: 0.1.0
* Author: Weston Ruter
* Author URI: https://weston.ruter.net/
* Text Domain: pwa
* License: GPL-2.0+
diff --git a/src/wp-includes/class-wp-block-type.php b/src/wp-includes/class-wp-block-type.php
index 33825a7888..d31aaf0b69 100644
--- a/src/wp-includes/class-wp-block-type.php
+++ b/src/wp-includes/class-wp-block-type.php
@@ -11,6 +11,7 @@
* Core class representing a block type.
*
* @since 5.0.0
+ * @property array[] $variations Block variations.
*
@westonruter
westonruter / bookmarklet.js
Created August 1, 2012 06:15
Run this script from console (or package as a bookmarklet) to export comments into a new window, suitable for inserting into a Google Doc
javascript: (function(){ var script = document.createElement('script'); script.src = "https://raw.github.com/gist/3224206/facebook-comment-exporter.js"; document.body.appendChild(script); }())
<?php
/**
* AMP Rewrite Endpoint Removal plugin.
*
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2019 Google Inc.
*
* @package AMP_Rewrite_Endpoint_Removal
*
<?php
/**
* Contact Form 7 Conditional Enqueues WordPress Plugin.
*
* @package CF7_Conditional_Enqueues
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2023 Google Inc.
*
* @wordpress-plugin
<?php
/**
* Strict CSP Plugin for WordPress 6.4-alpha.
*
* @package StrictCSP
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2023 Google Inc.
*
* @wordpress-plugin
<?php
/**
* Vary LCP Image Optimizations WordPress Plugin.
*
* @package VaryLcpImageOptimizations
* @author Weston Ruter, Google
* @license GPL-2.0-or-later
* @copyright 2023 Google Inc.
*
* @wordpress-plugin