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
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 / securing-acf.php
Created July 2, 2018 11:44
ACF's `the_field` function is insecure by default, here's a selection of wrappers that fix that
<?php
function the_field_url( $selector, $post_id=0, $format_value=true ) {
echo esc_url( get_field( $selector, $post_id, $format_value ) );
}
function the_field_url_raw( $selector, $post_id=0, $format_value=true ) {
echo esc_url_raw( get_field( $selector, $post_id, $format_value ) );
}
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
function widget:GetInfo()
return {
name = "Shard FX",
desc = "Adds glow effect at debug points",
author = "AF and Floris",
date = "May 2018",
license = "GNU GPL, v2 or later",
layer = 2,
enabled = true,
}
@tomjn
tomjn / wwwphpcs.php
Created May 9, 2018 18:13
BEHOLD probably one of the hackiest things I've done in a long time
<?php
require_once( 'vendor/squizlabs/php_codesniffer/autoload.php' );
// set the current working directory as the current directory
chdir( __DIR__ );
$_SERVER['argv'] = [
'phpcs',
'test.php',
'--report=json',
PlacementHandler = class(Module)
function PlacementHandler:Name()
return "PlacementHandler"
end
function PlacementHandler:internalName()
return "placementhandler"
end

Keybase proof

I hereby claim:

  • I am tomjn on github.
  • I am tomjn (https://keybase.io/tomjn) on keybase.
  • I have a public key whose fingerprint is ABB2 BBF9 EDA1 F2FD 3296 284E FF13 19DC 40DE 196D

To claim this, I am signing this object:

@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