Skip to content

Instantly share code, notes, and snippets.

View brandonpayton's full-sized avatar

Brandon Payton brandonpayton

View GitHub Profile
@brandonpayton
brandonpayton / .eslintrc
Last active May 30, 2018 10:40
annotated eslint config for Dojo 2 code conventions
{
"env": {
"browser": true,
"node": false,
"amd": false
},
"rules": {
"no-array-constructor": 2,
"no-dupe-keys": 2,
@brandonpayton
brandonpayton / gist:8919361
Created February 10, 2014 16:38
bir-example
define([
'intern!object',
'require',
'bir/RemoteRequire',
'bir/dijit',
'bir/value'
], function (registerSuite, require, RemoteRequire, dijit, value) {
registerSuite({
name: 'example',
@brandonpayton
brandonpayton / _StoreWidgetMixin.js
Last active August 29, 2015 13:57
Mixin for Store-based Widgets
define([
'dojo/_base/declare', 'dojo/dom-construct'
], function(declare, domConstruct) {
return declare(null, {
// summary:
// A mixin for creating a store-based widget
store: null,
query: null,
@brandonpayton
brandonpayton / autocomplete-abbreviations.js
Last active June 28, 2018 16:09
Run in dev tools console to add an abbreviation autocompleter for Gutenberg.
( function () {
function abbreviationCompleter( completers ) {
return {
name: 'abbreviation',
triggerPrefix: '::',
options: [
{ letters: 'FYI', expansion: 'For Your Information' },
{ letters: 'AFAIK', expansion: 'As Far As I Know' },
{ letters: 'IIRC', expansion: 'If I Recall Correctly' },
],
@brandonpayton
brandonpayton / index.js
Created December 19, 2018 07:42
A hack to show the Set Featured Image modal when a meta box button is clicked.
wp.domReady( function () {
var button = document.getElementById( 'mbwr-meta-box-button' );
var container = document.getElementById( 'mbwr-meta-box-media-upload' );
// NOTE: I'm not sure what timing issue this is avoiding, but it's necessary to avoid error.
setTimeout( function () {
wp.element.render(
wp.element.createElement( wp.editor.PostFeaturedImage ),
container
);
@brandonpayton
brandonpayton / main.rs
Created April 11, 2020 07:41
Rust generic type inference
fn get<T, U: From<T>>(s: T) -> U {
U::from(s)
}
fn main() {
let x: u64 = get(123u8);
println!("{:064b}", x);
}
@brandonpayton
brandonpayton / exercise.diff
Created March 22, 2024 17:08
WP Playground Exercise
diff --git a/packages/php-wasm/compile/php/Dockerfile b/packages/php-wasm/compile/php/Dockerfile
index fdc458d0..c97f8606 100644
--- a/packages/php-wasm/compile/php/Dockerfile
+++ b/packages/php-wasm/compile/php/Dockerfile
@@ -809,20 +809,21 @@ RUN set -euxo pipefail; \
"_wasm_set_content_type", \n\
"_wasm_set_cookies", \n\
"_wasm_set_path_translated", \n\
"_wasm_set_php_code", \n\
"_wasm_set_query_string", \n\
@brandonpayton
brandonpayton / PHP OOM log
Created March 27, 2024 01:57
Log of php-wasm leaking memory via partial munmap() attempts which fail
Initial memory limit: 64M
Initial memory usage: 0.38388824462891 MB
* iteration: 0
* strlen(): 0.0625 MB
* memory_get_usage(): 0.45029449462891 MB
* aggregate strlen()'s: 0.0625 MB
* iteration: 1
* strlen(): 0.125 MB
@brandonpayton
brandonpayton / index.php
Last active April 3, 2024 06:55
Script that revealed OOM condition due to memory leak
<?php
ini_set('memory_limit', '1G');
function useAllMemory() {
echo "Initial memory limit: " . ini_get( 'memory_limit' ) . '<br>';
echo "Initial memory usage: " . (memory_get_usage()/(1024*1024)) . ' MB <br>';
echo "<br>";
$data = '';
@brandonpayton
brandonpayton / sw.js
Created April 4, 2024 19:07
Sample of transpiled Service Worker script for playground.wordpress.net
function isURLScoped(e){return e.pathname.startsWith("/scope:")}function getURLScope(e){return isURLScoped(e)?e.pathname.split("/")[1].split(":")[1]:null}function setURLScope(e,t){let r=new URL(e);if(isURLScoped(r))if(t){const s=r.pathname.split("/");s[1]=`scope:${t}`,r.pathname=s.join("/")}else r=removeURLScope(r);else if(t){const s=r.pathname==="/"?"":r.pathname;r.pathname=`/scope:${t}${s}`}return r}function removeURLScope(e){if(!isURLScoped(e))return e;const t=new URL(e),r=t.pathname.split("/");return t.pathname="/"+r.slice(2).join("/"),t}const currentJsRuntime=function(){return typeof process<"u"&&process.release?.name==="node"?"NODE":typeof window<"u"?"WEB":typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?"WORKER":"NODE"}();if(currentJsRuntime==="NODE"){let e=function(r){return new Promise(function(s,n){r.onload=r.onerror=function(i){r.onload=r.onerror=null,i.type==="load"?s(r.result):n(new Error("Failed to read the blob/file"))}})},t=function(){const r=new Uint8Array([1,2,3,4]),n=new File