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
CREATE OR REPLACE FUNCTION sem_acentos(character varying) | |
RETURNS character varying AS | |
$BODY$ | |
SELECT translate($1, 'áéíóúàèìòùãõâêîôôäëïöüçÁÉÍÓÚÀÈÌÒÙÃÕÂÊÎÔÛÄËÏÖÜÇ', 'aeiouaeiouaoaeiooaeioucAEIOUAEIOUAOAEIOOAEIOUC') | |
$BODY$ | |
LANGUAGE 'sql' VOLATILE; |
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
//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] !== ' ' ) { |
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
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; |
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
/* 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; |
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
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 |
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
(function($) { | |
$.fn.tableappend = function(options) { | |
options = $.extend({ | |
items: null, | |
}, options); | |
if (!$(this).is('table')) | |
{ | |
console.error('Objeto ' + $(this).attr('id') + ' nao e tabela !'); | |
return; |
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
#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' |
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
do | |
$$ | |
declare | |
registro record; | |
begin | |
for registro in select id_aparelho, atualizado_assistencia from tbl_assistencia where tipo_assistencia = 1 and status_assistencia = 2 | |
loop | |
update tbl_aparelho set data_remanufaturado_aparelho = registro.atualizado_assistencia where id_aparelho = registro.id_aparelho; | |
end loop; | |
end; |
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
<select id="anexos"> | |
<option data-id="1">one</option> | |
<option data-id="2">two</option> | |
<option data-id="3">three</option> | |
</select> | |
$('#anexos').click(function(){ | |
$(this).find(':selected').data('id') | |
}); |
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 | |
// <img src="image.php?size=400x150&bg=eee&fg=999&text=Imagem+de+exemplo"/> | |
header ("Content-type: image/jng"); | |
// Dimensions | |
$getsize = isset($_GET['size']) ? $_GET['size'] : '100x100'; | |
$dimensions = explode('x', $getsize); | |
$image = imagecreate($dimensions[0], $dimensions[1]); | |
$bg = isset($_GET['bg']) ? $_GET['bg'] : 'ccc'; | |
$bg = hex2rgb($bg); | |
$setbg = imagecolorallocate($image, $bg['r'], $bg['g'], $bg['b']); |