Skip to content

Instantly share code, notes, and snippets.

View sirbrillig's full-sized avatar

Payton Swick sirbrillig

View GitHub Profile
@sirbrillig
sirbrillig / wpcom-proxy-request-temp-fix.diff
Last active July 7, 2017 16:08
Temporary fix for bug in wpcom-proxy-request in gravatar-upload code
commit 3c4a2b6c909adad9190bedcc34dec2810c5bb8a8
Author: Payton Swick <[email protected]>
Date: Wed Jul 5 16:45:45 2017 -0400
Data-layer: add temp fix for wpcom-proxy-request bug
See https://github.com/Automattic/wpcom-proxy-request/pull/20
diff --git a/client/state/data-layer/wpcom/gravatar-upload/index.js b/client/state/data-layer/wpcom/gravatar-upload/index.js
index 7761d9b..bc23161 100644
@sirbrillig
sirbrillig / functions.php
Last active November 20, 2024 09:52 — forked from UmeshSingla/functions.php
Post file using wp_remote_post in WordPress
<?php
$local_file = 'file_path'; //path to a local file on your server
$post_fields = array(
'name' => 'value',
);
$boundary = wp_generate_password( 24 );
$headers = array(
'content-type' => 'multipart/form-data; boundary=' . $boundary,
);
@sirbrillig
sirbrillig / BTVDev Slack CoC.md
Last active April 13, 2017 17:22
BTVDev Slack Code of Conduct
@sirbrillig
sirbrillig / bootstrap.php
Created January 3, 2017 18:44
Example phpunit test bootstrap file for using Patchwork
<?php
$autoload = 'vendor/autoload.php';
$patchwork = 'vendor/antecedent/patchwork/Patchwork.php';
# require patchwork first
if ( file_exists( $patchwork ) ) {
require_once $patchwork;
}
if ( file_exists( $autoload ) ) {
@sirbrillig
sirbrillig / simple-functional-component.js
Created January 2, 2017 18:27
An example of a simple stateless functional React component
import React from 'react';
export function Header( { title, subtitle, className } ) {
return (
<div className={ className }>
<h1>{ title }</h1>
<span>{ subtitle }</span>
</div>
);
}
@sirbrillig
sirbrillig / renderer-test.js
Last active December 23, 2016 20:43
A naive `renderToString()` that mimics `React.renderToStaticMarkup()`
/* globals describe, it */
import React from 'react';
import { expect } from 'chai';
// Using React.createElement works too!
import { renderToString, createElement } from './renderer';
describe( 'renderToString()', function() {
it( 'returns a string with a tag wrapping plain text for a component with one text child', function() {
window.registerBlock('My Block', function() { return '<p>this is my block</p>' })
@sirbrillig
sirbrillig / plug.js
Last active October 20, 2016 17:41
Babel plugin to convert simple React components to PHP
module.exports = function( babel ) {
const t = babel.types;
let insertedPhp = false;
const updateParamNameVisitor = {
Identifier( path ) {
if ( path.node.name.startsWith( '$' ) ) {
return;
}
// Transform VariableDeclarator Identifiers to PHP style
@sirbrillig
sirbrillig / add-methods-to-object.js
Last active August 2, 2016 15:47
Two different ways to add a method to an object without mutating the object prototype
"use strict"
class OriginalObj {
sayHello() {
console.log( 'hello' );
}
}
const myOriginal = new OriginalObj();
myOriginal.sayHello();
@sirbrillig
sirbrillig / MyTimeTest.php
Last active July 30, 2016 14:15
Convert a string timezone offset to a formatted string timezone offset
<?php
use PHPUnit\Framework\TestCase;
class MyTime {
/**
* Convert a float string timezone offset to a DateTimeZone
*
* @param string $number The initial offset float, as a string.
* @return DateTimeZone The converted DateTimeZone
*/