Skip to content

Instantly share code, notes, and snippets.

Julio Vedovatto juliovedovatto

Block or report user

Report or block juliovedovatto

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View puppeter-savepdf-vue.js
import puppeteer from 'puppeteer'
const browser = await puppeteer.launch({
args: [
'--no-sandbox'
],
timeout: 10000
})
const page = await browser.newPage()
@juliovedovatto
juliovedovatto / Wordpress: Autoptimize, exclude js from combine and monification
Created Dec 6, 2018
Autoptimize is a exelente wordpress plugin, but it seems it ignore the blacklist from "Exclude scripts from Autoptimize" option. The plugin persists to minify and combine, instead of leaving it as it is. So I found this filter, that I can check the url and check agains the blacklist. If the js item is blacklisted, Autoptimize will skip it.
View Wordpress: Autoptimize, exclude js from combine and monification
<?php
// theme functions.php
add_filter('autoptimize_filter_js_minify_excluded', function ($condition, $url) {
if (!$blacklist = get_option('autoptimize_js_exclude', false))
return true;
$blacklist = array_filter(array_map('trim', explode( ',', $blacklist)));
return count(array_filter($blacklist, function ($match) use ($url) {
@juliovedovatto
juliovedovatto / remove_duplicates_array_multi.js
Created Dec 3, 2016
Javascript: Remove duplicates of multidimensional array
View remove_duplicates_array_multi.js
// for browser using, this code requires javascript 1.7+
var arr = [
{ foo: 'bar', lorem: 'ipsum' },
{ foo: 'bar', lorem: 'ipsum' },
{ foo: 'bar', lorem: 'ipsum dolor sit amet' }
];
arr = arr.map(JSON.stringify).reverse() // convert to JSON string the array content, then reverse it (to check from end to begining)
.filter(function(item, index, arr){ return arr.indexOf(item, index + 1) === -1; }) // check if there is any occurence of the item in whole array
@juliovedovatto
juliovedovatto / Deploybot Ignore
Last active Aug 16, 2018
Exclude certain paths from being uploaded
View Deploybot Ignore
node_modules
**/node_modules
**/*.md
**/*.json
**/.gitignore
**/gulpfile.js
**/Gruntfile.js
**/package-lock.json
**/package.json
@juliovedovatto
juliovedovatto / in_array.js
Created Nov 25, 2016
Javascript: check if the given element is in array
View in_array.js
function in_array(value, array) {
if (array.constructor !== Array)
return false;
return array.filter(function(item) { return item == value; }).length > 0;
}
// example
in_array(2, [1,2,3, "foo", "bar"]); // true
@juliovedovatto
juliovedovatto / swap_elements_array.js
Last active Nov 25, 2016
Javascript snippet to swap elements in array
View swap_elements_array.js
// one line code to swap elements in array
arr[x] = [arr[y],arr[y] = arr[x]][0];
@juliovedovatto
juliovedovatto / random_number.js
Last active Nov 15, 2016
random_number: javascript function to sort a number in a given range. Supports blacklisting array of numbers.
View random_number.js
function random_number(min, max, blacklist) {
min = min || 0;
max = max || 0;
var random = Math.floor(Math.random() * (max - min + 1)) + min;
if (!blacklist || blacklist.constructor !== Array)
return random;
else if (typeof blacklist == 'string')
blacklist = [ blacklist ];
@juliovedovatto
juliovedovatto / image_blur.js
Created Nov 9, 2016
node gm - keep Aspect Ratio on resize and fill with blur background (with imagemagick)
View image_blur.js
var GM = require('gm').subClass({ imageMagick: true }),
Q = require('q'), // promisses support
fs = require('fs'),
path = require('path');
function create_thumb(img, dest_img, width, height) {
var deferred = Q.defer();
Q.when(get_image_size(img)).then(function (size) {
var thumb_width = width,
View ecmascript_6_array_shuffle.js
// METHOD 1
Object.assign(Array.prototype, {
shuffle() {
let m = this.length, i;
while (m) {
i = (Math.random() * m--) >>> 0;
[this[m], this[i]] = [this[i], this[m]];
}
return this;
}
@juliovedovatto
juliovedovatto / foo.php
Created Mar 1, 2016
PHP: array_flatten - método para deixar array multidimensional com 1 dimensão apenas.
View foo.php
/**
* Função para deixar uma array multidimensional em 1 índice apenas.
* @see http://stackoverflow.com/a/1320259/390946
* @author Julio Vedovatto <juliovedovatto@gmail.com>
* @param array $array
* @return array
*/
function array_flatten(array $array) {
$return = array();
You can’t perform that action at this time.