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
@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;
@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 / 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
// 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(', ');
#!/bin/sh
error() { echo "$@" 1>&2; }
domain_files=$1
if [ -z $domain_files ]; then
error "What is the file with the domains?"
exit 1
fi
@dhyegocalota
dhyegocalota / unique_words.js
Created July 8, 2016 18:21
Unique Words (by line)
const fs = require('fs');
var data = [];
var file = fs.readFileSync(process.argv[2], {encoding: 'utf-8'});
file
.split('\n')
.forEach(x => {
if (data.indexOf(x) === -1) {
data.push(x);
@dhyegocalota
dhyegocalota / migrate.sh
Created September 16, 2016 13:09
imapsync
#!/bin/sh
error() { echo "$@" 1>&2; }
file=$1
if [ -z $file ]; then
error "Usage \`./migrate credentials.txt\`"
exit 1
fi
@dhyegocalota
dhyegocalota / hackaflag.js
Created March 19, 2017 21:01
[Hackflag] Web server
var wrongContent = 'nadaaquinadaaquinadaaquinadaaquinadaaquinadaaquinadaaquinadaaquinadaaquinadaaquinadaaquinadaaquinadaaquinadaaquinadaaquinadaaquinadaaquinadaanadanadaaaannaannaanndnna';
var filesToTest = Array.from(document.querySelectorAll('td a')).filter(x => x.href.match(/\.php$/));
const testContent = (file) => {
return (response) => {
response.text()
.then(text => {
if (text.trim() != wrongContent) {
console.log(`O arquivo '${file.href}' tem o content: '${text}'`);
@dhyegocalota
dhyegocalota / picker.js
Created April 18, 2017 20:51
[React Native] Picker for Native Base + React Native Navigation (by Wix)
// @flow
import React, { Component } from 'react';
import {
connectStyle,
Container,
Content,
ListItem,
Text,
Radio,
@dhyegocalota
dhyegocalota / highligh.sh
Created May 6, 2017 14:06
Syntax Highlight
# Custom functions
function light() {
if [ -z "$2" ]
then src="pbpaste"
else
src="cat $2"
fi
$src | highlight -O rtf --syntax $1 --style solarized-light --font-size 18 | pbcopy
}