Skip to content

Instantly share code, notes, and snippets.

@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 / 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();
@matesnippets
matesnippets / _z-index.scss
Created September 6, 2015 19:01
Sass, z-index mixin for smart z-index management
// ----
// z-index mixin to help organize z-indexes
// ----
// Start with a map
$z-layers: (
"cog": 50,
"overlay": 40,
"toc": 30,
"iframe-loader": 25,
@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 / escaper.js
Created September 5, 2015 19:22
JavaScript, escape a string
/**
* Use the browsers native capability to escape strings
*/
'use strict';
define(function() {
// Use the browser's built-in functionality to quickly and safely escape the
// string
return function(str) {
var div = document.createElement('div');
div.appendChild(document.createTextNode(str));
@matesnippets
matesnippets / cookies.js
Created August 7, 2015 07:18
JavaScript, cookies, set read and erake cookies
/**
* Simple module for making cookies
*/
'use strict';
define(function() {
return {
createCookie: function(name, value, days) {
var expires;
if (days) {
var date = new Date();
@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;