Skip to content

Instantly share code, notes, and snippets.

View dhyegocalota's full-sized avatar
🎯
I build results through Software Engineering.

Dhyego Calota dhyegocalota

🎯
I build results through Software Engineering.
View GitHub Profile
// var products = [{ sku: 1 }, { sku: 2 }]; // Sample data (SKU of products from Magento Database)
var productsSku = products
.map(product => (product.sku || '').toString())
.map(sku => sku.split(' ').filter(node => node.match(/^\S+$/)))
.reduce((acc, target) => Array.prototype.concat.apply(acc, target))
.filter((value, index, self) => self.indexOf(value) === index)
.map(sku => `'${sku}'`)
.sort((x, y) => x - y)
.join(', ');
@dhyegocalota
dhyegocalota / pattern.txt
Created April 28, 2016 15:15
Helper to format tasks from excel (regex)
// CTRL+F
Match pattern: (.+)[\t\s]+([0-9]+\:[0-9]+\:[0-9]+)[\t\s]+(.+)
Replace pattern: [$2] $1 - $3
@dhyegocalota
dhyegocalota / AWStats.js
Created April 28, 2016 15:15
AWStats helper (from nexcess.net)
function bytes(e,r){return"string"==typeof e?parse(e):"number"==typeof e?format(e,r):null}function format(e,r){if(!numberIsFinite(e))return null;var a=Math.abs(e),t=r&&r.thousandsSeparator||"",n=r&&void 0!==r.decimalPlaces?r.decimalPlaces:2,i=Boolean(r&&r.fixedDecimals),o="B";a>=map.tb?o="TB":a>=map.gb?o="GB":a>=map.mb?o="MB":a>=map.kb&&(o="kB");var m=e/map[o.toLowerCase()],s=m.toFixed(n);return i||(s=s.replace(formatDecimalsRegExp,"$1")),t&&(s=s.replace(formatThousandsRegExp,t)),s+o}function parse(e){if("number"==typeof e&&!isNaN(e))return e;if("string"!=typeof e)return null;var r=parseRegExp.exec(e);if(null===r)return null;var a=parseFloat(r[1]),t=(r[4]||"b").toLowerCase();return Math.floor(map[t]*a)}var formatThousandsRegExp=/\B(?=(\d{3})+(?!\d))/g,formatDecimalsRegExp=/(?:\.0*|(\.[^0]+)0+)$/,map={b:1,kb:1024,mb:1<<20,gb:1<<30,tb:1024*(1<<30)},numberIsFinite=Number.isFinite||function(e){return"number"==typeof e&&isFinite(e)},parseRegExp=/^((-|\+)?(\d+(?:\.\d+)?)) *(kb|mb|gb|tb|b)?$/i;
var isResumeNode = (
@dhyegocalota
dhyegocalota / decorator
Created September 30, 2015 12:31 — forked from johgusta/decorator
Disable JIT compiler on Safari for $new
angular.module('lib.decorators', [])
.config(['$provide', function($provide){
'use strict';
var isSafari = /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor);
if(isSafari) {
$provide.decorator('$rootScope', ['$delegate', function($rootScope) {
var scopePrototype = Object.getPrototypeOf($rootScope);
var originalScopeNew = scopePrototype.$new;