Skip to content

Instantly share code, notes, and snippets.

View enricolucia's full-sized avatar

Enrico Lucia enricolucia

View GitHub Profile
@enricolucia
enricolucia / flattenArray.js
Created March 27, 2018 09:14
Deep array flatten function
// SOLUTION:
// Turns out that the following is the most performant in terms of ops per seconds.
// It iterates on an array, staying within the "while loop" as long as
// the current item exists. Checking also whether using concat to the very same "arr" argument
// or push methods in a new stack array until no items are left within the "arr" argument
const flattenLoop = arr => {
let stack = []
let item
while (item = arr.shift()) {
@enricolucia
enricolucia / flattenArray.js
Created August 24, 2016 00:57
Function that will flatten an array of arbitrarily nested arrays of integers into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4].
/**
* Flattens passed in array.
*
* @param {Array} input is the array to flatten.
* @returns {out} returns flattened array.
*/
function flatten(input) {
let i,
placeHolder = [input],

LESS Coding Guidelines

Inspired on "LESS Coding Guidelines of The Obvious Corporation" ang "Git styleguide"

Naming Conventions

Never reference js- prefixed class names from CSS files. js- are used exclusively from JS files. Use the is- prefix for state rules that are shared between CSS and JS. Classes and IDs are lowercase with words separated by a dash:

Right:

@enricolucia
enricolucia / request.js
Created January 15, 2015 15:15
XMLHTTPRequest Polyfill
function makeRequest(url,callback,context) {
var httpRequest = null;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
try {
httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {