Skip to content

Instantly share code, notes, and snippets.

View maurobringolf's full-sized avatar
⛰️

Mauro Bringolf maurobringolf

⛰️
  • Zürich, Switzerland
View GitHub Profile
//defining a normal property o.x using getters and setters
var o = {
c: 1,
get x() { return this.c; },
set x(y) { this.c = y; }
}
o.x; //1
o.x = 3;
o.x; //3
//Defining a restricted access property o.x using getters and setters
var o = {
c: 0,
get x() { return this.c; },
set x(y) { this.c = Math.max(y,0); }
}
o.x = 3;
o.x; //3
//defining a pseudo-private property o.x using getters and setters
var o = {
__c: 1,
get x() { return this.__c; },
set x(y) { this.__c = y; }
}
//Make the property o.__c non-enumerable
Object.defineProperty(o, '__c', { enumerable: false });
@maurobringolf
maurobringolf / url-ebnf.txt
Last active January 15, 2017 13:07
A first try at a EBNF for URLs
lowercase_letter = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
uppercase_letter = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"
letter = lowercase_letter | uppercase_letter
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
alphanumeric = letter | digit
lowercase_alphanumeric = lowercase_letter | digit
hyphen = "-" | "_"
lowercase_word = lowercase_alphanumeric { lowercase_alphanumeric }
<?php
echo "Running full GET requests... \n";
$sum = 0;
for( $i = 1; $i <= 100; ++$i ) {
$start = microtime(true);
<?php
function get_remote_data( $slug ) {
$key = 'some-key-string';
if( !wp_cache_get( $key ) ) {
$response = wp_remote_get( $url );
//error handling
<?php
is_numeric( $var ); //http://php.net/manual/de/function.is-numeric.php
is_array( $var ); //http://php.net/manual/de/function.is-array.php
is_object( $var ); //http://php.net/manual/de/function.is-object.php
is_string( $var ); //http://php.net/manual/de/function.is-string.php
isset( $data['key'] ); //http://php.net/manual/de/function.isset.php
in_array( $var, $arr ); //http://php.net/manual/de/function.is-array.php
<?php
sanitize_text_field( $str ); //https://developer.wordpress.org/reference/functions/sanitize_text_field/
sanitize_title( $str ); //https://developer.wordpress.org/reference/functions/sanitize_title/
sanitize_email( $str ); //https://developer.wordpress.org/reference/functions/sanitize_email/
sanitize_file_name( $str ); //https://developer.wordpress.org/reference/functions/sanitize_file_name/
<?php
esc_html( $str ); //https://developer.wordpress.org/reference/functions/esc_html/
esc_attr( $str ); //https://developer.wordpress.org/reference/functions/esc_attr/
esc_url( $str ); //https://developer.wordpress.org/reference/functions/esc_url/
esc_js( $str ); //https://developer.wordpress.org/reference/functions/esc_js/
esc_textarea( $str ); //https://developer.wordpress.org/reference/functions/esc_textarea/
<?php
/**
* Plugin Name: Singleton Example
* Plugin URI: https://github.com/maurobringolf/wordpress-plugin-singleton
* Description: An empty illustration of a WordPress plugin implemented as singleton
* Author: Mauro Bringolf
* Author URI: https://maurobringolf.ch
* Version: 1.0
* Text Domain: singleton
* Domain Path: languages