I was trying to understand JavaScript Promises by using various libraries (bluebird, when, Q) and other async approaches.
I read the spec, some blog posts, and looked through some code. I learned how to
/* bling.js */ | |
window.$ = document.querySelector.bind(document); | |
window.$$ = document.querySelectorAll.bind(document); | |
Node.prototype.on = window.on = function(name, fn) { this.addEventListener(name, fn); }; | |
NodeList.prototype.__proto__ = Array.prototype; | |
NodeList.prototype.on = function(name, fn) { this.forEach((elem) => elem.on(name, fn)); }; |
<?php | |
/** | |
* Custom API REST path class | |
* | |
* @package MyPlugin | |
* @author Skatox | |
*/ | |
class WC_API_Custom extends WC_API_Resource | |
{ |
#!/bin/bash | |
set -e | |
if ([ "$1" == "install" ] || [ "$1" == "i" ]) && [ "$#" -ne 1 ]; then | |
for var in "$@" | |
do | |
if [ "$var" == "--save" ] || [ "$var" == "--save-dev" ] || [ "$var" == "-S" ] || [ "$var" == "-D" ] || [ "$var" == "-g" ]; then | |
has_modifier=true | |
fi |
'use strict'; | |
import Singleton from 'Singleton'; | |
class ClassA extends Singleton { | |
constructor() { | |
super(); | |
} | |
singletonMethod1() { | |
// ... |
I was trying to understand JavaScript Promises by using various libraries (bluebird, when, Q) and other async approaches.
I read the spec, some blog posts, and looked through some code. I learned how to
function getType (value) { | |
let type = typeof value; | |
if (type === 'object') { | |
return value ? Object.prototype.toString.call(value).slice(8, -1) : 'null'; | |
} | |
return type; | |
} | |
[NaN, 0, 1, Infinity, // numbers | |
null, undefined, false, 'str', // other primitives |
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: