Skip to content

Instantly share code, notes, and snippets.

View mcunha98's full-sized avatar
🏠
Working from home

Mauricio Cunha mcunha98

🏠
Working from home
View GitHub Profile
@mcunha98
mcunha98 / alterar-engine-mysql.sql
Last active March 9, 2020 17:33
Usado para alterar todas as tabelas de um engine para outro
#Vai gerar a instrucao SQL para ser executada para as tabelas que satisfazem a query
#Altera o engine do banco de dados definido
SET @DATABASE_NAME = 'name_of_your_db';
#Neste caso altera de MyISAM para InnoDB, altere como desejado
SELECT CONCAT('ALTER TABLE `', table_name, '` ENGINE=InnoDB;') AS sql_statements
FROM information_schema.tables AS tb
WHERE table_schema = @DATABASE_NAME
AND `ENGINE` = 'MyISAM'
AND `TABLE_TYPE` = 'BASE TABLE'
@mcunha98
mcunha98 / jquery-append-array-to-table-rows.js
Created February 25, 2020 19:01
append rows to html table based on array
(function($) {
$.fn.tableappend = function(options) {
options = $.extend({
items: null,
}, options);
if (!$(this).is('table'))
{
console.error('Objeto ' + $(this).attr('id') + ' nao e tabela !');
return;
DO $$
DECLARE r RECORD;
BEGIN
FOR r IN SELECT * FROM t LOOP
BEGIN
UPDATE t SET id = 2 WHERE des = 'foo' AND id = r.id;
UPDATE t SET des = 'bar2' WHERE id = 2 AND id = r.id;
EXCEPTION WHEN unique_violation THEN
/* Simples upsert em postgres */
DO $$
BEGIN
UPDATE x SET b = b + 1 WHERE a = 1;
IF (NOT FOUND) THEN
INSERT INTO x VALUES (1, 1);
END IF;
END;
CREATE DEFINER=`root`@`%` PROCEDURE `banco`.`nome_da_sp`()
BEGIN
declare v_id_pedido int;
declare v_id_produto int;
declare v_id_tamanho int;
declare v_id_cor int;
declare v_qtde int;
declare v_antes int;
declare v_depois int;
declare v_inserted int;
//Exemplo de como adicionar metodos a objetos padrao do js como string
//para conter metodos declarativos
function capitalizeSentence ( str ) {
if ( ! str ) { str = this; }
let sentences = str.split('.');
let updated = [];
sentences.map( function (sentence) {
if ( sentence ) {
// if the first character is not space
if ( sentence[0] !== ' ' ) {
CREATE OR REPLACE FUNCTION sem_acentos(character varying)
RETURNS character varying AS
$BODY$
SELECT translate($1, 'áéíóúàèìòùãõâêîôôäëïöüçÁÉÍÓÚÀÈÌÒÙÃÕÂÊÎÔÛÄËÏÖÜÇ', 'aeiouaeiouaoaeiooaeioucAEIOUAEIOUAOAEIOOAEIOUC')
$BODY$
LANGUAGE 'sql' VOLATILE;
(function($) {
$.fn.serializeFiles = function() {
var form = $(this);
var formData = new FormData();
var formParams = form.serializeArray();
$.each(form.find('input[type="file"]'), function(i, tag) {
$.each($(tag)[0].files, function(i, file) {
formData.append(tag.name, file);
});
});
@mcunha98
mcunha98 / index.html
Created July 25, 2020 16:43
The Future of Ugmonk
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<style type="text/css">
@media only screen and (max-width:480px){body,table,td,p,a,li,blockquote{-webkit-text-size-adjust:none !important}body{width:100% !important;min-width:100% !important}td[id=bodyCell]{padding:10px !important}table.kmMobileHide{display:none !important}table[class=kmTextContentContainer]{width:100% !important}table[class=kmBoxedTextContentContainer]{width:100% !important}td[class=kmImageContent]{padding-left:0 !important;padding-right:0 !important}img[class=kmImage]{width:100% !important}td.kmMobileStretch{padding-left:0 !important;padding-right:0 !important}table[class=kmSplitContentLeftContentContainer],table[class=kmSplitContentRightConte
//esperado que as colunas da row tenham rel iniciando com sc-
//exemplo
//#row10 sc-nome
//#row10 sc-cpf
//etc...
function syncResponse(response, rid = "#row-")
{
if (typeof response.data !== 'undefined')
{
var highlight = false;