Skip to content

Instantly share code, notes, and snippets.

View tomjn's full-sized avatar
🎯
Focusing

Tom J Nowell tomjn

🎯
Focusing
View GitHub Profile
🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦🟦
🟦🟦🟦🟨🟨🟨🟨🟦🟦🟦🟦
🟦🟦🟨🟨🟨🟨⬛🟨🟦🟦🟦
🟦🟨🟨⬛🟨🟨⬛🟨🟨🟦🟦
🟦🟨🟨⬛🟨🟨🟨🟨🟨🟦🟦
🟦🟨🟨🟨🟨🟨🟨🟨🟨🟦🟦
🟦🟨🟨🟨⬛⬛🟧🟧🟨🟦🟦
🟦🟦🟨🟨🟧🟧🟧🟧🟧🟧🟦
🟦🟦🟦🟨🟨🟨🟨🟧🟧🟧🟦
🟦🟦🟦🟦🟦🟦🟦🟧🟧🟦🟦
@tomjn
tomjn / gist:6140909
Last active February 21, 2020 06:35
If you're thinking of using WP_Query, try using this iterator instead, cleaner boilerplate, auto-cleans up after itself
<?php
$pages = new query_loop( array(
'post_type' => 'page'
));
foreach( $pages as $id => $post ) {
the_title();
// etc...
}
@tomjn
tomjn / typekit.editor.php
Created September 10, 2012 10:22
Typekit fonts for TinyMCE editor plugin
add_filter("mce_external_plugins", "tomjn_mce_external_plugins");
function tomjn_mce_external_plugins($plugin_array){
$plugin_array['typekit'] = get_template_directory_uri().'/typekit.tinymce.js';
return $plugin_array;
}
@tomjn
tomjn / gist:194136e3ecbe693cf1749c4622ea00a3
Created January 15, 2019 01:15
Provisioner log of tideways utility
==> default: Running provisioner: utility-mte90-tideways (shell)...
default: Running: /var/folders/jx/3t2z3sgx7sb3mwlml6v2xskh0000gp/T/vagrant-shell20190115-33101-1pdjm18.sh
default: Installing Tideways & XHgui
default: File copied for php 7.0
default: cp:
default: cannot stat ‘/home/vagrant/tideways.ini’
default: : No such file or directory
default: cp:
default: cannot stat ‘/home/vagrant/mongodb.ini’
default: : No such file or directory
<?php
function toms_addition_endpoint( \WP_REST_Request $request ) {
$result = $request['a'] + $request['b'];
return rest_ensure_response( $result );
}
function toms_addition_routes() {
register_rest_route( 'tomjn/v1', '/addition', array(
DataStore = {
data = {},
subscribers = {}
}
function DataStore:new (o)
o = o or {} -- create object if user does not provide one
setmetatable(o, self)
self.__index = self
return o
end
@tomjn
tomjn / helloworld.php
Last active July 3, 2018 11:50
An example of how to use the class defined here: https://gist.github.com/Tarendai/6089867
<?php
require_once( 'custom_page.php' );
class Hello_World_Page extends Tomjn_Custom_Page {
public function render_page() {
echo 'hello world!';
}
}
@tomjn
tomjn / custom_page.php
Last active July 3, 2018 11:50
A base class used to create arbitrary content at arbitrary URLs in WordPress without needing a post or listing/archive to host it
<?php
/**
* A helper class to implement arbitrary content at arbitrary URLs without a supporting post or page.
* Inherit from this class and implement the render_page method
*
* @author: Tom J Nowell ww.tomjn.com
* @License: GPL 2+
*/
abstract class Tomjn_Custom_Page {
ai = ....
p = {x=0,y=0,z=0}
units = UnitQuery( ai, {
within={
position=p
radius=100
},
canMove=false
})
PlacementHandler = class(Module)
function PlacementHandler:Name()
return "PlacementHandler"
end
function PlacementHandler:internalName()
return "placementhandler"
end