A Pen by Max Dolgov on CodePen.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function template(source, scope = {}) { | |
return String(source).replace(/\{\{(.+?)\}\}/gm, function(match, p1) { | |
const param = p1.trim() | |
return scope[param] || '' | |
}).replace(/ +/mg, ' ') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Client side, you typically see the template style changed to {{ }} like so... | |
_.templateSettings = { | |
interpolate : /\{\{(.+?)\}\}/gim, | |
evaluate: /\{\#(.+?)\#\}/gim | |
}; | |
/* | |
However, in Node.js, this causes issues when trying to render a template. | |
Likely, you haven't paid too much attention to the fact that you are setting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
function replacer() { | |
var objects = []; | |
return function(key, value) { | |
if (typeof value === 'object' && value !== null) { | |
var found = objects.some(function(existing) { | |
return (existing === value); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @title objectUtils.js | |
* @description magical comprehensions for JS Object instances | |
* @author Max L Dolgov, plugn@github.com | |
* | |
* Here is `var` keyword for ability to re-declare functions, | |
* it makes tweaking functions in browser console possible. | |
* | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* php.es6 | |
* @description PHP functions implemented in JavaScript/ES6 | |
* @author Max L Dolgov <bananafishbone@gmail.com> | |
*/ | |
function count(value) { return value.length } | |
function chr(num) { return String.fromCharCode(num) } | |
function ord(str) { return String(str).charCodeAt(0) } | |
function trim(str) { return String(str).trim() } | |
function substr(str, start, length) { return String(str).substr(start, length) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<!-- HBox and VBox layouts have been implementated with many libraries/toolkits on | |
different platforms and languages (like ExtJS,QT,GTK,.NET...). | |
This tries to achieve the same but with CSS only. | |
Supported browsers: IE 10+, Safari 6.1, Latest FF, Chrome --> | |
<style type="text/css"> | |
html, body { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// console.log `this` | |
{ | |
console: { | |
log: function log() | |
}, | |
scriptArgs: [], | |
print: function print(), | |
__loadScript: function __loadScript(), | |
os: { | |
O_APPEND: 8, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
#include <functional> | |
#include <vector> | |
template <typename T, typename U> | |
U foldLeft(const std::vector<T>& data, | |
const U& initialValue, | |
const std::function<U(U,T)>& foldFn) { | |
typedef typename std::vector<T>::const_iterator Iterator; |