Skip to content

Instantly share code, notes, and snippets.

View zonaro's full-sized avatar
🎤
Beatbox & Code

Kaizonaro zonaro

🎤
Beatbox & Code
View GitHub Profile
@zonaro
zonaro / GenerateClass.sql
Last active February 5, 2024 18:02
Generate Dart Classes from table or Views
CREATE OR ALTER PROCEDURE [dbo].[GenerateDartClass] (@TableName sysname = null)
AS
BEGIN
DECLARE @Result VARCHAR(MAX) = ''
DECLARE the_cursor CURSOR FAST_FORWARD
FOR
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE (TABLE_TYPE = 'BASE TABLE' OR TABLE_TYPE = 'VIEW') AND ISNULL(@TableName, TABLE_NAME) = TABLE_NAME
@zonaro
zonaro / SqlMapperExtensions.cs
Last active July 7, 2023 16:43
This file add overloads for each Dapper.SQLMapper method, allowing the use of FormattableString for building parametrized queries. Each parameter of string will be converted into a SQL parameter.
using System.Data;
using System.Globalization;
using System.Text.RegularExpressions;
/*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This file add overloads for each Dapper.SQLMapper method, allowing the use of FormattableString *
* for building parametrized queries. Each parameter of string will be converted into a SQL parameter. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
@zonaro
zonaro / IfBlank.sql
Last active March 30, 2023 11:59
IfBlank function for SQL Server
-- =============================================
-- Author: Zonaro
-- Create date: 30/03/2023
-- Description: Return a replacement value if expression is null or contains only whitespace
-- =============================================
CREATE FUNCTION IfBlank
(
@expression varchar(max),
@replacement varchar(max)
)
@zonaro
zonaro / notificationOverAlert.js
Last active April 13, 2023 19:31
notificationOverAlert.js
window.oldAlert = window.alert
window.alert = function (message) {
var __notification = null;
if (!("Notification" in window)) {
window.oldAlert(message);
} else if (Notification.permission === "granted") {
__notification = new Notification(message);
} else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
@zonaro
zonaro / GenerateClass.sql
Last active November 22, 2022 11:52
Generate C# Classes from table or Views
create or ALTER procedure [dbo].[GenerateClass] (@TableName sysname = null, @GenerateProperties bit = 1, @PlainTextClass bit = 0)
as
BEGIN
declare @Result varchar(max) = 'namespace ' + replace(replace(replace(DB_NAME(),' ','_'),'.','_'),'~','_') + '
{'
DECLARE the_cursor CURSOR FAST_FORWARD
FOR SELECT TABLE_NAME
@zonaro
zonaro / CreateUPSERTProcedure.sql
Last active December 1, 2022 15:03
Create a UPSERT procedure from table name (SQL Server)
CREATE or ALTER PROC [dbo].[CreateInsertUpdateProcedure]
@TableName sysname,
@AutoCreate bit = 0
as
if((select count(TABLE_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @TableName)>1)
begin
declare @variables as varchar(max) = 'create or alter proc piu'+@TableName+CHAR(13)
@zonaro
zonaro / DataMesAno.sql
Last active February 9, 2024 18:39
Retorna o primeiro ou o ultimo dia do mes a partir da MesAno especificada (4 digitos)
-- =============================================
-- Author: Zonaro
-- Create date: 26/01/2022
-- Description: Retorna o primeiro ou o ultimo dia do mes a partir da MesAno especificada (4 digitos)
-- =============================================
CREATE OR ALTER FUNCTION [dbo].[DataMesAno]
(
@MesAno varchar(4), -- Exemplo '0123' => Janeiro/2023
@FimDoMes bit = 0 -- 1 para 31-01-2023 | 0 para 01-01-2023
)
@zonaro
zonaro / jquery.autogroup.js
Created July 23, 2019 16:11
auto group option in optgroup by attribute
$.fn.autoGroup = function (selector) {
var elem = $(this);
let a = [];
selector = selector || "data-group";
elem.find("option").appendTo(elem); //remove options dentro de optgroups e coloca no select
elem.find("optgroup").remove(); // remove optgroups
elem.find("[" + selector + "]").each(function (index) {
a.push($(this).attr(selector));