This file contains 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
/** | |
* Evita submeter várias vezes o mesmo formulário ao clicar no botão | |
* submete o form e logo em seguida desativa o botão | |
* que volta a ficar ativo novamente depois do tempo definido em | |
* throttleTime, que por padrão é 30 segundos | |
* | |
* @param button | |
* @param form | |
* @param throttleTime |
This file contains 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
/** | |
* | |
* @param func | |
* @param duration | |
* @returns {function(...[*]=): void} | |
*/ | |
const throttle = function (func, duration) { | |
let shouldWait = false | |
return function (...args) { | |
if (!shouldWait) { |
This file contains 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 que aguarda um tempo antes de executar uma requisição ou ação | |
* evitando realizar multiplas vezes em um evento, um autocomplete por exemplo | |
* | |
* @param fn | |
* @param delay | |
* @returns {function(): void} | |
*/ | |
const debounce = function (fn, delay) { | |
let timer = null; |
This file contains 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
-- show running queries (pre 8.2) | |
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query | |
FROM pg_stat_activity | |
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%' | |
ORDER BY query_start desc; | |
-- show running queries (9.2) | |
SELECT pid, age(clock_timestamp(), query_start), usename, query | |
FROM pg_stat_activity | |
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' |
This file contains 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
public class Test { | |
private void exportPermissionDataToExcel(SortedMap allPermissions, HttpServletResponse response) { | |
PropertyManager props = ResourcesProperties.getInstance(); | |
HSSFWorkbook wb = null; | |
try { | |
String headerString = "attachment; filename=\"" + EXCEL_FILE_NAME + ".xls\";"; |
This file contains 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
/** | |
* Enum com todas as Unidades da Federação do Brasil. Contém o nome da Unidade, a sigla e a capital da Unidade da Federação. | |
* | |
* @author Ricardo Giaviti | |
* @version 1.0.0 | |
* @since 1.0.0 | |
*/ | |
public enum UnidadeFederacao { | |
AMAZONAS("Amazonas", "AM", "Manaus"), |
This file contains 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 | |
/** | |
* Method generateRandomNumber | |
* | |
* Gera um número incrivelmente grande. Mas deve-se tomar cuidado | |
* com o limite de memória definido no php e | |
* o limite de tempo de execução de um script. | |
* Levando em consideração que cada caractere/digito consome 1 byte de memória | |
* 1.000.000 caracteres consumirá aproximadamente 1,2MB |
This file contains 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
// Padrão iterator - Exemplo 1 | |
var names = (function () { | |
var list = ['Matheus', 'Felipe', 'Jose', 'Kennedy', 'Andre', 'Ailton']; | |
var index = 0; | |
var next = function () { | |
if (!this.hasNext()) { | |
return null; | |
} | |
return list[index++]; | |
}; |
This file contains 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
// Padrão Singleton (pode ser uma declaração literal) | |
// ou com construtor: | |
function Singleton() { | |
if (typeof Singleton.instance === "object") { | |
return Singleton.instance; | |
} | |
this.value = "Teste"; | |
Singleton.instance = this; |
This file contains 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
// padrão Sandbox. Exemplo 1 | |
var Sandbox = function () { | |
// converter os arguments num array | |
var args = Array.prototype.slice.call(arguments); | |
var callback = args.pop(); // ultimo argumento | |
var orderedModules = args.pop(); | |
if(this instanceof Sandbox) { | |
new Sandbox(orderedModules, callback); | |
} |
NewerOlder