This file contains hidden or 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
/** | |
* Função para deixar uma array multidimensional em 1 índice apenas. | |
* @see http://stackoverflow.com/a/1320259/390946 | |
* @author Julio Vedovatto <[email protected]> | |
* @param array $array | |
* @return array | |
*/ | |
function array_flatten(array $array) { | |
$return = array(); | |
This file contains hidden or 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
// 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; | |
} |
This file contains hidden or 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
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, |
This file contains hidden or 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 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 ]; |
This file contains hidden or 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
// one line code to swap elements in array | |
arr[x] = [arr[y],arr[y] = arr[x]][0]; |
This file contains hidden or 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 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 |
This file contains hidden or 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
// 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 |
This file contains hidden or 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
node_modules | |
**/node_modules | |
**/*.md | |
**/*.json | |
**/.gitignore | |
**/gulpfile.js | |
**/Gruntfile.js | |
**/package-lock.json | |
**/package.json |
This file contains hidden or 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 | |
// 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) { |
This file contains hidden or 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
import puppeteer from 'puppeteer' | |
const browser = await puppeteer.launch({ | |
args: [ | |
'--no-sandbox' | |
], | |
timeout: 10000 | |
}) | |
const page = await browser.newPage() | |
OlderNewer