Skip to content

Instantly share code, notes, and snippets.

View jboulhous's full-sized avatar

Jamal Boulhous jboulhous

  • Morocco, Africa
View GitHub Profile
@jboulhous
jboulhous / wc-bookings-availability-search.php
Created February 25, 2019 09:15 — forked from apintocr/wc-bookings-availability-search.php
WooCommerce Bookings Availability Search
<?php
/**
* WooCommerce Bookings Availability Search
*
* This is almost pseudo code, it only serves to explain the "how to do it" and does not attempt to be "The Way" to do it.
* NOTE: This NEEDS to be refined in order to work as expected.
*
* @author António Pinto <[email protected]>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
@jboulhous
jboulhous / dropzonejs-wp-rest-api.js
Last active April 28, 2018 16:06 — forked from soderlind/dropzonejs-wp-rest-api.js
DropzoneJS & WordPress REST API
/*
Uploading images is a two step process (from https://github.com/WP-API/WP-API/issues/1768#issuecomment-160540932):
POST the data to /wp/v2/media - this can either be as the request body, or in multipart format. This will upload the file, and give you a 201 Created response with a Location header. This header points to the post object for the attachment that has just been created.
PUT the post data to the endpoint returned in the Location header (which will look something like /wp/v2/media/{id}).
I do step 2 (PUT), if POST is a success, in myDropzone.on("success", function(file, response){}
*/
// dropzoneWordpressRestApiForm is the configuration for the element that has an id attribute
@jboulhous
jboulhous / upload-a-file.MD
Created April 28, 2018 16:06 — forked from websupporter/upload-a-file.MD
Upload a file using the WordPress REST API

Upload files

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:

@jboulhous
jboulhous / test-lib.js
Created March 19, 2018 06:49
Backbone small test library
class Test extends Backbone.Model {
constructor(model = {}, klass = {}) {
var args = {};
if (model instanceof Backbone.Model) {
args = model;
} else if (_.isFunction(model)) {
args = {name: _.result(model, "name"), fn: model};
} else {
args = model;
}
@jboulhous
jboulhous / tip.md
Created February 13, 2018 00:25
twentyseventeen child theme enqueue styles
@jboulhous
jboulhous / prepare.sh
Last active March 4, 2019 23:15
prepare wordpress on c9
# Do not run this script directly.
# instead copy/paste one or several lines.
# be carefull to wp-cli prompt mode.
# command ending with --prompt must be run alone.
# wp-cli
# Download wp-cli
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Verifying my Blockstack ID is secured with the address 1CZSDcDfGL7kupu4FuTk3GNBnZeLtSPZBX https://explorer.blockstack.org/address/1CZSDcDfGL7kupu4FuTk3GNBnZeLtSPZBX
@jboulhous
jboulhous / scriptify.js
Last active January 29, 2018 00:04
inject jquery underscore backbone into page window
/*
Version 0.0.1, 2018
Copyright (C) 2018 Jamal Boulhous (]d).
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Ok, the purpose of this license is simple
and you just
@jboulhous
jboulhous / archive-downloads.js
Last active October 23, 2017 15:10
Archive downloads in YYYY-MM folders
/*
call this way:
node script.js /path/to/Downloads/folder
*/
const fs = require('fs');
const path = require('path');
function now () { return new Date() }
@jboulhous
jboulhous / getGistFile.js
Created February 24, 2016 00:34
get gist file with $.ajax
function getGistFile (gist, filename, cb) {
$.ajax({
url: 'https://api.github.com/gists/' + gist,
type: 'GET',
dataType: 'jsonp'
}).success( function(gistdata) {
var content = gistdata.data.files[filename].content;
cb(null, JSON.parse(content))
}).error( function(e) {
cb(e)