Skip to content

Instantly share code, notes, and snippets.

View nachodd's full-sized avatar

Ignacio Durand nachodd

  • Expero
  • Rosario, Santa Fé, Argentina
View GitHub Profile
@nachodd
nachodd / averange_multidimensional_array.js
Created October 11, 2019 20:21
Average Multidimensional Array Javascript (recursive)
const averange = (input) => {
const {sum, count} = sumAndCount(input)
return sum/count
}
const sumAndCount = (arr) => {
let count = 0
const sum = arr.reduce((acc, element) => {
<?php
class helpers {
public function uniqueCode($length = 10) {
$characters = '0123456789';
$charactersLength = strlen($characters);
while (true) {
// uniqid gives 13 chars, but you could adjust it to your needs.
if (function_exists("random_bytes")) {
$bytes = random_bytes($length);
} elseif (function_exists("openssl_random_pseudo_bytes")) {
@nachodd
nachodd / recursive_explore.php
Created November 17, 2016 13:43
Recursively walks a Collection or Array that contains children of the same kind and flatten into an single dimesion Collection or Array
<?php
// Recursively walks a Collection or Array that contains children of the same kind and flatten into an single dimesion Collection or Array.
// Example:
// We have:
// A
// |_B
// |_C
// |_D
// We want:
@nachodd
nachodd / example-modal.js
Created December 16, 2013 04:01
modal bootstrap & javascript objects
//Modal cargando
var dialogs = (function () {
var cargandoDiv = $('#cargandoDialog');
var avisoDiv = $('#modalAviso');
return {
showCargando: function() {
cargandoDiv.modal();
},
hideCargando: function () {
cargandoDiv.modal('hide');
This is question is old but I found you can do this based on information from a tutorial by Tejas Jasani: http://www.theappguruz.com/blog/upgrading-from-laravel-4-2-to-5-in-web
Here are the key steps:
1 - Add the app/Http/Controllers directory to the "autoload" classmap directive of your composer.json file.
"autoload": {
"classmap": [
"database",
"app/Http/Controllers"
],
<?php
function utf8_converter($array) {
array_walk_recursive($array, function(&$item, $key){
if(!mb_detect_encoding($item, 'utf-8', true)){
$item = utf8_encode($item);
}
});
return $array;
}
@nachodd
nachodd / checkEmail.js
Created October 4, 2013 18:36
Function that checks email with regular expressions. Funcion que chequea un email a traves de una expresion regular
function checkEmail(email) {
email = email.toLowerCase();
if(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/.test(email)==false ) {
return false;
}
return t
@nachodd
nachodd / rotate.js
Created October 4, 2013 18:42
Function that shifts array positions. (see example) Funcion que rota las posiciones de un array. (ver ejemplo) FUENTE: http://stackoverflow.com/questions/1985260/javascript-array-rotate CREDITOS: http://stackoverflow.com/users/48015/christoph
/*
FUENTE: http://stackoverflow.com/questions/1985260/javascript-array-rotate
CREDITOS: http://stackoverflow.com/users/48015/christoph
*/
Array.prototype.rotate = (function() {
var unshift = Array.prototype.unshift,
splice = Array.prototype.splice;
return function(count) {
var len = this.length >>> 0,
@nachodd
nachodd / watch.js
Last active December 24, 2015 16:49
Javascript Object Watcher pollyfill. Doesn't support IE8. (>=IE9) "Observador" para Objetos de Javascript - Arreglado para compatibilidad. No soporta IE8. (>= IE9) Se puede utilizar para monitorear cambios en los atributos de objetos en JS, disparando un callback
/*
FUENTE: https://gist.github.com/eligrey/384583
*/
/*
* object.watch polyfill
*
* 2012-04-03
*
* By Eli Grey, http://eligrey.com
@nachodd
nachodd / toFixedDown.js
Created October 4, 2013 18:38
Extends the Number object, adding a method to fix down some value. Extiende al objeto Number, añadiendo un metodo para redondear para abajo un valor.
Number.prototype.toFixedDown = function(digits) {
var n = this - Math.pow(10, -digits)/2;
n += n / Math.pow(2, 53); // added 1360765523: 17.56.toFixedDown(2) === "17.56"
return n.toFixed(digits);
}