Skip to content

Instantly share code, notes, and snippets.

@matesnippets
matesnippets / debounce.js
Created June 9, 2015 21:26
JavaScript, debounce AMD module
'use strict';
define(function() {
/**
* Returns a function, that, as long as it continues to be invoked, will not
* be triggered. The function will be called after it stops being called for
* N milliseconds. If `immediate` is passed, trigger the function on the
* leading edge, instead of the trailing.
*/
var debounce = function(func, wait, immediate) {
var timeout;
@matesnippets
matesnippets / classList.js
Created January 14, 2015 15:44
JavaScript, classList shim
/*
* classList.js: Cross-browser full element.classList implementation.
* 2014-07-23
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
/*global self, document, DOMException */
@matesnippets
matesnippets / body_class_prefix.php
Created March 10, 2015 16:59
PHP, WordPress, Prepend a namespace in WordPress body_class() function, so that it won't clash with other class names. E.g. `root--`.
/**
* Prepend a namespace in WordPress body_class() function
* @param string $prefix The desired prefix
* @param string $classes Additional classes separated by single space
* @return string Single space separated list of classes
*/
function body_class_prefix($prefix, $classes = '')
{
global $wp_query;
$output = '';
@matesnippets
matesnippets / closest.js
Created February 23, 2015 20:00
JavaScript, Get closest element by class. Mimics the jQuery's `.closest()` with pure JavaScript.
define(function() {
/**
* Get the closest element of a given element by class
*
* Take an element (the firt param), and traverse the DOM upward from it
* untill it hits the element with a given class name (second parameter).
* This mimics jquery's `.closest()`.
*
* @param {element} el The element to start from
* @param {string} clazz The class name
@matesnippets
matesnippets / multi-explode.php
Created October 10, 2016 15:08
A recursive function to parse a multidimensional array from a string
/**
* A recursive function to parse a multidimensional array from a string
*
* @param array $delimiter Array of delimiters
* @param string $string The string to parse
* @return array Multidimensional array
*/
function n26_multi_explode(array $delimiter, $string) {
// Shift the array
$d = array_shift($delimiter);
@matesnippets
matesnippets / multi-explode
Created October 10, 2016 15:04
A recursive function to parse a multidimensional array from a string
A recursive function to parse a multidimensional array from a string
@matesnippets
matesnippets / substitute-values.js
Created May 13, 2016 08:28
Replaces placeholder values, or text, or attributes in the DOM.
'use strict';
define(function () {
var substitute = {};
substitute.placeholders = function (target, replaceObject) {
_replaceStuff(target, replaceObject, 'placeholders');
};
substitute.attribute = function (target, replaceObject) {
@matesnippets
matesnippets / .eslintrc
Last active December 12, 2015 16:07
JavaScript, Link, My curret ESLint settings
env:
browser: true
rules:
brace-style: [2, "stroustrup", { "allowSingleLine": true }]
comma-style: [2, "last"]
default-case: 2
# func-style: [2, "expression"]
guard-for-in: 2
indent: [2, 4, {"SwitchCase": 1}]
@matesnippets
matesnippets / .scss-lint.yml
Last active December 10, 2015 19:03
Sass, my scss-lint settings file
linters:
SelectorFormat:
enabled: true
convention: strict_BEM
Indentation:
enabled: true
width: 4
ColorKeyword:
@matesnippets
matesnippets / call-api.php
Created November 18, 2015 19:27
PHP, simply REST API caller function
/**
* Call an API
*
* @param string $method HTTP verb: POST, PUT, GET etc
* @param stinrg $url URL
* @param boolean $data Plunk the data tot he URL: array("param" => "value") ==> index.php?param=value
* @return request Whatever the API returns
*/
function n26_call_api($method, $url, $data = false) {
$curl = curl_init();