Skip to content

Instantly share code, notes, and snippets.

View sirbrillig's full-sized avatar

Payton Swick sirbrillig

View GitHub Profile
@sirbrillig
sirbrillig / index.php
Last active October 4, 2019 00:43
Example of PHP shell helper injection and test
<?php
// If this function were a class method, the injection could happen in the constructor instead
function printMessageAndExit(string $message, ?ShellHelper $shell): void {
$shell = $shell ?? new DefaultShell();
$shell->echo($message);
$shell->exit();
}
interface ShellHelper {
@sirbrillig
sirbrillig / Phabricator-Notification-Grouping.js
Last active December 17, 2018 18:07
Allows collapsing Phabricator notifications to one-per-revision
// ==UserScript==
// @name Phabricator Notification Grouping
// @namespace https://gist.github.com/sirbrillig/6473dff58511c1672d644af33f078535
// @version 0.1
// @description Allows collapsing Phabricator notifications to one-per-revision
// @author Payton Swick <[email protected]>
// @match https://code.a8c.com/notification/*
// @grant none
// ==/UserScript==
@sirbrillig
sirbrillig / Vegan_Haggis.md
Last active April 30, 2018 17:17
My vegan haggis recipe

Vegan Haggins and Neeps and Tatties

Ingredients

  • 6 medium russet potatoes, roughly chopped
  • 1 large rutabaga, roughly chopped
  • 1/2 stick of margarine
  • salt and pepper to taste
  • 1 large onion, chopped
  • 2 medium carrots, grated
@sirbrillig
sirbrillig / bootstrap.php
Created December 5, 2017 22:41
Bootstrap for writing phpcs sniff tests
<?php
require_once(__DIR__ . '/../vendor/squizlabs/php_codesniffer/tests/bootstrap.php');
require_once(__DIR__ . '/SniffTestHelper.php');
@sirbrillig
sirbrillig / SniffTestHelper.php
Created December 5, 2017 22:19
A helper class for testing phpcs sniffs
<?php
use PHP_CodeSniffer\Files\LocalFile;
use PHP_CodeSniffer\Ruleset;
use PHP_CodeSniffer\Config;
class SniffTestHelper {
public function prepareLocalFileForSniffs($sniffFiles, string $fixtureFile): LocalFile {
$config = new Config();
$ruleset = new Ruleset($config);
@sirbrillig
sirbrillig / cpx
Last active December 1, 2017 09:08
Shortcut to run commands in vendor/bin for PHP Composer projects
#!/usr/bin/env php
<?php
$vendorBinDirectory = './vendor/bin';
$helpMessage = "Shortcut to run commands in vendor/bin for Composer projects
Usage: cpx <command>
<command> must be an executable file in the vendor/bin directory.
Read about vendor binaries here:
@sirbrillig
sirbrillig / Maybe.php
Last active December 11, 2017 22:05
A simple implementation of a `Maybe` return class in PHP.
<?php
class Maybe {
private $value;
private $error;
private function __construct($value, $error) {
$this->value = $value;
$this->error = $error;
}
@sirbrillig
sirbrillig / phpcs.xml
Last active September 26, 2024 06:22 — forked from Ovsyanka/ruleset.xml
PHPCS rules for PSR2 with tabs, same-line braces, and missing variable detection
<?xml version="1.0"?>
<ruleset name="PaytonsStandard">
<description>
Originally from https://gist.github.com/Ovsyanka/e2ab2ff76e7c0d7e75a1e4213a03ff95
PSR2 with changes:
- tabs instead of spaces (https://gist.github.com/gsherwood/9d22f634c57f990a7c64)
- bracers on end of line instead new line
- unused/undefined variable detection (https://github.com/sirbrillig/phpcs-variable-analysis)
</description>
<arg name="tab-width" value="4"/>
@sirbrillig
sirbrillig / button-2.diff
Created August 16, 2017 21:35
Button-2: Fix Headstart image size
Index: button-2/inc/headstart/en.json
===================================================================
--- button-2/inc/headstart/en.json (revision 45326)
+++ button-2/inc/headstart/en.json (working copy)
@@ -95,7 +95,7 @@
"hs_custom_meta": "_hs_first_post",
"hs_sharing": 1,
"hs_like_status": 1,
- "attachment_url": "https:\/\/headstartdata.files.wordpress.com\/2016\/04\/pexels-photo-30732.jpg",
+ "attachment_url": "https:\/\/headstartdata.files.wordpress.com\/2017\/08\/pexels-photo-30732-small.jpg",
diff --git a/index.js b/index.js
index bd240d0..afa5674 100644
--- a/index.js
+++ b/index.js
@@ -165,7 +165,7 @@ export default function request( options, fn ) {
if ( body && formData ) {
debug( 'API ignoring body because formData is set. They cannot both be used together.' );
}
- if ( body && ! formData ) {
+ if ( body ) {