Skip to content

Instantly share code, notes, and snippets.

View bitflower's full-sized avatar

Matthias Max bitflower

View GitHub Profile
<?php
/*
* Notes:
*
* activate the json-rest-api plugin - then add this code to your functions.php file
*
* now the following ajax call should work:
*
jQuery.ajax({
class MAP_API_DemoItemType extends WP_JSON_CustomPostType {
protected $base = '/map/demo';
protected $type = 'demo';
public function register_routes( $routes ) {
$routes = parent::register_routes( $routes );
return $routes;
}
}
@bitflower
bitflower / gist:75034fe5eda50ee21784
Created December 30, 2014 17:26
More nice fonts for Chrome :-)
@media screen {
html {
-webkit-font-smoothing: antialiased;
}
}
@bitflower
bitflower / gist:1a7efbcbec19079414d0
Created December 30, 2014 18:05
Activate CORS for WP-API (JSON REST API)
/**
* bitflower: Activate CORS for WP-API (JSON REST API)
*/
do_action("json_api", $controller, $method);
add_action( 'json_api', function( $controller, $method )
{
# DEBUG
// wp_die( "To target only this method use <pre><code>add_action('$controller-$method', function(){ /*YOUR-STUFF*/ });</code></pre>" );
header( "Access-Control-Allow-Origin: *" );
}, 10, 2 );
@bitflower
bitflower / classie.js
Last active August 29, 2015 14:12 — forked from desandro/classie.js
/*!
* classie - class helper functions
* from bonzo https://github.com/ded/bonzo
*
* classie.has( elem, 'my-class' ) -> true/false
* classie.add( elem, 'my-new-class' )
* classie.remove( elem, 'my-unwanted-class' )
*/
/*jshint browser: true, strict: true, undef: true */
@bitflower
bitflower / gist:bd7b9cceead1ff914e75
Created January 8, 2015 07:09
Stop scroll bouncing on touch devices
// Stop scroll bouncing
document.ontouchmove = function(e) {
e.preventDefault();
};
@bitflower
bitflower / gist:e63cf54f8c6af27e39c5
Created January 9, 2015 11:49
Activate CORS in PHP
// First line of first PHP file
header( "Access-Control-Allow-Origin: *" );
@bitflower
bitflower / gist:65d8d9fd46f2a10c5795
Created January 12, 2015 10:22
Add CORS support to DaftMonk/angular-fullstack YO generator
1. npm install cors
2. then in the app module:
var cors = require('cors');
//add cors to do the cross site requests
app.use(cors());
app.filter('trusthtml', ['$sce', function ($sce) {
return function(t) {
return $sce.trustAsHtml(t)
}
}]);
@bitflower
bitflower / gist:ee1d9146cc687894498d
Created January 15, 2015 06:45
Cut decimal number after 2 digits
// You could use Math.floor and some additional arithmetics:
Math.floor(15.7784514000 * 100) / 100
// Or convert the number into a string, match the number up to the second decimal place and turn it back into a number:
Number(15.7784514000.toString().match(/^\d+(?:\.\d{0,2})?/))
// Then you can still call toFixed to get a string with a fixed number of decimal places.