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
CREATE OR REPLACE FUNCTION sem_acentos(character varying)
RETURNS character varying AS
$BODY$
SELECT translate($1, 'áéíóúàèìòùãõâêîôôäëïöüçÁÉÍÓÚÀÈÌÒÙÃÕÂÊÎÔÛÄËÏÖÜÇ', 'aeiouaeiouaoaeiooaeioucAEIOUAEIOUAOAEIOOAEIOUC')
$BODY$
LANGUAGE 'sql' VOLATILE;
//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 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;
/* 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;
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
@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;
@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'
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;
<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')
});
@mcunha98
mcunha98 / image.php
Created December 5, 2019 00:04
Placeholder image only in PHP ,create a JPG file
<?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']);