Skip to content

Instantly share code, notes, and snippets.

View luzeduardo's full-sized avatar

Eduardo Luz luzeduardo

  • Porto
  • 04:28 (UTC)
View GitHub Profile
@luzeduardo
luzeduardo / memoization.js
Last active April 5, 2018 03:09
memoization.js
const mem = (fn) => {
const cache = {}
return (...args) => {
if (cache[args]) {
return cache[args]
}
const res = fn.apply(this, args)
cache[args] = res
return res
@luzeduardo
luzeduardo / flattner
Created January 21, 2018 11:56
JS flatt depth arrays
export const flattner = array => {
if (!Array.isArray(array)) {
throw Error(`${array} is not an Array`)
}
for (let i = 0; i < array.length;) {
let value = array[i]
if (Array.isArray(value)) {
if (value.length > 0) {
value.unshift(i, 1)
array.splice.apply(array, value)
/**
* jquery.mask.js
* @version: v1.14.8
* @author: Igor Escobar
*
* Created by Igor Escobar on 2012-03-10. Please report any bug at http://blog.igorescobar.com
*
* Copyright (c) 2012 Igor Escobar http://blog.igorescobar.com
*
* The MIT License (http://www.opensource.org/licenses/mit-license.php)
function solution($S) {
$len = strlen($S);
if(!$len){
return 0;
}
$data = str_split($S, 1);
$datasize = count($data) + 1;
$chunked = array_chunk($data, $datasize / 2);
@luzeduardo
luzeduardo / .bash_profile
Created October 8, 2013 01:44
bash_profile diplaying git branch and alias for sublime and mysql
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin
eval "$(rbenv init -)"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
source ~/.git-completion.bash
alias edit='open -a "Sublime Text 2"'
alias mysql=/usr/local/mysql/bin/mysql
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
# Bash completion
if [ -f /etc/bash_completion ]; then
@luzeduardo
luzeduardo / mysql_dbbck_splitter.sh
Last active December 23, 2015 10:49
Backup mysql database splitting table by table
#!/bin/bash
if [ "$1" == "" ]; then
echo "Usage: $0 <database> [output-path] [user] [password] [server_address]"
exit 1
fi
if [ "$2" == "" ]; then
echo "Usage: $0 <database> [output-path] [user] [password] [server_address]"
exit 1
@luzeduardo
luzeduardo / import
Last active December 19, 2015 10:19
Import from multiple sql files
#!/bin/bash
db=$1
user=$2
passwd=$3
if [ "$db" = "" ]; then
echo "Usage: $0 db_name user password"
exit 1
fi
clear
for sql_file in *.sql; do
<?php
umask(0);
ini_set('memory_limit','512M');
set_time_limit(0);
if(file_exists('app/Mage.php')) require 'app/Mage.php';
else require '../../app/Mage.php';
// Init without cache so we get a fresh version
Mage::app('admin','store', array('global_ban_use_cache' => TRUE));
@luzeduardo
luzeduardo / Varnish_Magento_vcl
Created March 21, 2013 19:32
Varnsh Magento vcl version 3
# This is a basic VCL configuration file for varnish by Ideaspool.
#
# Default backend definition. Set this to point to your content
# server.
#
backend default {
.host = "192.168.0.116";
.port = "80";
}
acl trusted {
@luzeduardo
luzeduardo / ExampleSeleniumLoop
Last active July 14, 2016 20:21
Selenium loop example with Selenium IDE + https://github.com/darrenderidder/sideflow
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="http://localhost" />
<title>ExampleSeleniumLoop</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">