Skip to content

Instantly share code, notes, and snippets.

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

Bruno Dantas brunotdantas

🏠
Working from home
View GitHub Profile
<?php
/***********************************************************
MYSQL VERSION
************************************************************/
$username="root"; $password=""; $database="exam_codes";
$con = mysql_connect("localhost",$username,$password) or die( "Unable to Connect database");
mysql_select_db($database,$con) or die( "Unable to select database");
// Table Name that you want
// to export in csv
@brunotdantas
brunotdantas / downloadSheet.php
Created November 22, 2018 12:16
Create a spreadsheet with phpSpreadSheet (https://github.com/PHPOffice/PhpSpreadsheet) #Excel #xls #xlsx
<?php
// requiring autoload with the pluguin
require __DIR__ . '/../../vendor/autoload.php';
// invoking needed classes
use PhpOffice\PhpSpreadsheet\Spreadsheet; //class responsible to change the spreadsheet
use PhpOffice\PhpSpreadsheet\Writer\Xlsx; //class that write the table in .xlsx
$spreadsheet = new Spreadsheet(); //instanciando uma nova planilha
@brunotdantas
brunotdantas / estados_Brasil.sql
Last active November 28, 2018 18:10
Lista dos estados do Brasil com relacionamento de tabelas de País > Estado > Cidade
-- Orinal em Mysql : https://www.ricardoarrigoni.com.br/cidades-brasil-lista-de-cidades-brasileiras-em-sql/
--------------------------------------------
--> Scrip abaixo cria estrutura de Pais > Estado > Cidade
--------------------------------------------
-- < Cria tabela de países > --
IF EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'[dbo].[paises]') )
DROP TABLE paises; -- < Dropa a tabela se já existir > --
CREATE TABLE paises (
@brunotdantas
brunotdantas / read_xml.sql
Created December 3, 2018 13:34
Example of reading a XML using OPENXML in SQL SERVER
DECLARE @XML XML
SET @XML = '<rows><row>
<transacao>
<IdInvernadero>8</IdInvernadero>
<IdProducto>3</IdProducto>
<cars>
<id>z</id>
<test> oi</test>
</cars>
<IdCaracteristica1>8</IdCaracteristica1>
@brunotdantas
brunotdantas / Validacao CPF receita federal
Created February 15, 2019 12:25
Validacao CPF receita federal
var foco = "";
var msgstatus = "";
// fonte: http://www.receita.fazenda.gov.br/aplicacoes/atcta/cpf/funcoes.js
/*************************************************
Função que permitir digitar numeros
**************************************************/
function EntradaNumerico(evt) {
var key_code = evt.keyCode ? evt.keyCode :
evt.charCode ? evt.charCode :
@brunotdantas
brunotdantas / sqlcmd_batch.bat
Last active March 3, 2020 18:16
Run sql in batches from a folder #sql #SQLSERVER #TSQL
:: Source: https://www.sqlservercentral.com/scripts/run-sqlt-sql-scripts-on-folder
:: A bat script to run all the sql/t-sql scripts in a specific folder.
::
:: Features:
::
:: - Using SQLCMD for running the scripts.
::
:: - Logging the results of your sql to a file per script.
::
:: - Input for scripts and log folders.
/*
Solução pro erro:
Mensagem 1755, Nível 16, Estado 0, Linha 22
Não podem ser criados padrões em colunas de carimbo de data/hora do tipo de dados. Tabela 'STG_MSAF_SALES_HEADER', coluna 'created_timestamp'.
Mensagem 1750, Nível 16, Estado 0, Linha 22
Não foi possível criar a restrição ou o índice. Consulte os erros anteriores.
quando feito:
ALTER TABLE STG_MSAF_SALES_HEADER ADD created_timestamp timestamp default getdate()
--https://stackoverflow.com/questions/662383/better-techniques-for-trimming-leading-zeros-in-sql-server/662437#662437
SELECT SUBSTRING(IDCLIENTE, PATINDEX('%[^0]%', IDCLIENTE+'.'), LEN(IDCLIENTE)) ,* FROM TB_IN_SAP_CUSTOMER WHERE CNPJ IN ( 'zzzzzz')
@brunotdantas
brunotdantas / query-api-ajax
Created February 20, 2020 23:12
Ajax example with promises
// Use this solution when we need to do an action when the request is finished
var myPromise = function(){
return new Promise(function(resolve,reject){
var xhr = new XMLHttpRequest();
xhr.open('GET','https://api.github.com/users/brunotdantas');
xhr.send(null); // if you have any parameters to complement the request
xhr.onreadystatechange = function(){
if(xhr.readyState === 4){
@brunotdantas
brunotdantas / script-bkp.sql
Last active March 3, 2020 18:14
T-SQL script to backup local database
-- #tags #sql #backup #bkp #sqlcmd #scheduler #windows
-- run this via batch
-- sqlcmd -S localhost -U [username] -P [password] -d master -Q "exec sp_BackupDatabases '[databaseName]','[typeOfBackup]', '[directoryToSaveData]'"
-- https://support.microsoft.com/en-us/help/2019698/how-to-schedule-and-automate-backups-of-sql-server-databases-in-sql-se
-- =============================================
-- Author: Microsoft
-- Create date: 2010-02-06
-- Description: Backup Databases for SQLExpress