Skip to content

Instantly share code, notes, and snippets.

View tomjn's full-sized avatar
🎯
Focusing

Tom J Nowell tomjn

🎯
Focusing
View GitHub Profile
<?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
@adrienbrault
adrienbrault / llama2-mac-gpu.sh
Last active January 22, 2024 07:39
Run Llama-2-13B-chat locally on your M1/M2 Mac with GPU inference. Uses 10GB RAM. UPDATE: see https://twitter.com/simonw/status/1691495807319674880?s=20
# Clone llama.cpp
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
# Build it
make clean
LLAMA_METAL=1 make
# Download model
export MODEL=llama-2-13b-chat.ggmlv3.q4_0.bin
@dkjensen
dkjensen / filters.php
Last active April 3, 2024 21:05
WordPress Gutenberg Query Loop View More AJAX
<?php
/**
* Add data attributes to the query block to describe the block query.
*
* @param string $block_content Default query content.
* @param array $block Parsed block.
* @return string
*/
function query_render_block( $block_content, $block ) {
global $wp_query;

Force Gutenberg to Fullscreen Mode

This is an example snippet for forcing the Gutenberg editor into full screen mode in anticipation of the change coming to WordPress 5.4.

function logColor(color, args) {
console.log(`%c ${args.join(' ')}`, `color: ${color}`);
}
const log = {
aliceblue: (...args) => { logColor('aliceblue', args)},
antiquewhite: (...args) => { logColor('antiquewhite', args)},
aqua: (...args) => { logColor('aqua', args)},
aquamarine: (...args) => { logColor('aquamarine', args)},
azure: (...args) => { logColor('azure', args)},
@ahmadawais
ahmadawais / upload-a-file.MD
Created June 18, 2017 11:07 — forked from websupporter/upload-a-file.MD
Upload a file using the WordPress REST API

Upload files

Using the REST API to upload a file to WordPress is quite simple. All you need is to send the file in a POST-Request to the wp/v2/media route.

There are two ways of sending a file. The first method simply sends the file in the body of the request. The following PHP script shows the basic principle:

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@olih
olih / jq-cheetsheet.md
Last active April 17, 2024 19:46
jq Cheet Sheet

Processing JSON using jq

jq is useful to slice, filter, map and transform structured json data.

Installing jq

On Mac OS

brew install jq

@mboynes
mboynes / trait-alley-cli-bulk-task.php
Last active November 16, 2022 18:09
WP-CLI methods to iterate over any number of posts efficiently and reliably
<?php
// DEPRECATED. See https://github.com/alleyinteractive/wp-bulk-task as the successor to this trait.
/**
* Chunk up the task when you need to iterate over many posts.
*
* For instance, to iterate over every post on the site and add post meta:
*
* $this->bulk_task( function( $post ) {
@tomjn
tomjn / readme.md
Last active March 19, 2016 00:38
Copy paste into the terminal on OS X to download and install everything needed for VVV, then create a VVV vagrant box in ~/vvv

Open the "Terminal" application in MacOS X, then copy paste the script and press enter. It will install VVV and all its dependencies.

It will also install an additional site that will show how to add your own sites ( site-name.dev ).

When finished, it will do several things:

  • Open your www folder in Finder for editing
  • Open the VVV webpage for information
  • Open the CFTP Site init scaffold with information on how to add your own sites