Skip to content

Instantly share code, notes, and snippets.

View Ninjanaut's full-sized avatar

Ninjanaut

  • Czech Republic, Prague
View GitHub Profile
@Ninjanaut
Ninjanaut / Fill-empty-values-in-the-dataset.sql
Created July 10, 2022 22:58
Fill empty values based on the value in previous rows
declare @temp as table (
DayDate date not null,
Inventory int null
)
insert into @temp
values
('01-01-2022', 1234),
('02-01-2022', null),
('03-01-2022', null),
@Ninjanaut
Ninjanaut / azure-sql-get-table-sizes.sql
Created May 23, 2022 19:58
Get table sizes from Azure SQL database
-- https://dataedo.com/kb/query/azure-sql/list-of-tables-by-their-size
-- Get table sizes from Azure SQL database
select schema_name(tab.schema_id) + '.' + tab.name as [table],
cast(sum(spc.used_pages * 8)/1024.00/1024.00 as numeric(36, 2)) as used_gb,
cast(sum(spc.total_pages * 8)/1024.00/1024.00 as numeric(36, 2)) as allocated_gb
from sys.tables tab
inner join sys.indexes ind
on tab.object_id = ind.object_id
inner join sys.partitions part
on ind.object_id = part.object_id and ind.index_id = part.index_id
@Ninjanaut
Ninjanaut / listen_to_new_messages.py
Created November 9, 2021 10:02
Telegram Telethon API
from telethon import TelegramClient, events
api_id = 123456
api_hash = '<someHash>'
channel = '@someChannel'
client = TelegramClient('session', api_id, api_hash)
@client.on(events.NewMessage(chats=channel))
async def my_event_handler(event):
@Ninjanaut
Ninjanaut / foreach-with-index.md
Created November 1, 2021 10:41
foreach-with-index
using System.Collections.Generic;
using System.Linq;

namespace Web.Utility.Extensions
{
    public static class IEnumerableExtensions
    {
        public static IEnumerable<(T item, int index)> WithIndex<T>(this IEnumerable<T> self) => self?.Select((item, index) => (item, index)) ?? new List<(T, int)>();
 }
@Ninjanaut
Ninjanaut / create-azure-sql-login.md
Last active October 21, 2021 11:21
Create login and user in Azure SQL database to prevent VA1143 vulnerability
-- Create Login
CREATE LOGIN ApplicationUser 
WITH PASSWORD = 'foo secured password';

-- Preconditions:
-- Connected to Azure SQL specific database
--------------------------------------------

-- Create User
@Ninjanaut
Ninjanaut / delete-azure-provisioned-wiki.md
Last active October 21, 2021 11:15
Delete AzureDevOps provisioned wiki pages

install Azure CLI

https://docs.microsoft.com/en-us/cli/azure/install-azure-cli

install devops extension

az extension add --name azure-devops