Skip to content

Instantly share code, notes, and snippets.

View karthiks's full-sized avatar
🎯
Focusing

Karthik Sirasanagandla karthiks

🎯
Focusing
View GitHub Profile
@karthiks
karthiks / index_stats.sql
Created November 23, 2021 07:12
Get statistics on Index using DMVs in SQL Server
// Get usage statistics on Index using DMVs in SQL Server
// Reference: https://www.sqlshack.com/gathering-sql-server-indexes-statistics-and-usage-information/
SELECT OBJECT_NAME(IX.OBJECT_ID) Table_Name
,IX.name AS Index_Name
,IX.type_desc Index_Type
,SUM(PS.[used_page_count]) * 8 IndexSizeKB
,IXUS.user_seeks AS NumOfSeeks
,IXUS.user_scans AS NumOfScans
,IXUS.user_lookups AS NumOfLookups
@karthiks
karthiks / bulk-copy-method-examples.sql
Created November 11, 2021 07:25
Bulk Copy in SQL Server
# This one is bash, bcoz bcp is a cmd line utility
# https://docs.microsoft.com/en-us/sql/tools/bcp-utility?view=sql-server-ver15#examples
# WideWorldImporters can be downloaded from https://github.com/Microsoft/sql-server-samples/releases/tag/wide-world-importers-v1.0
bcp WideWorldImporters.Warehouse.StockItemTransactions out D:\BCP\StockItemTransactions_character.bcp -c -T
# Bulk Insert
BULK INSERT YourTargetTable FROM '\\shared\directory\sourcedata.txt';
BULK INSERT Sales.Invoices
FROM 'inv-2017-12-08.csv'
@karthiks
karthiks / table-valued-udf.sql
Created November 6, 2021 14:32
Table-Valued UDF
CREATE OR ALTER FUNCTION dbo.AgeStatus
(
@AGE INT
)
RETURNS CHAR(10)
AS
BEGIN
DECLARE @status CHAR(5);
IF @AGE < 18
SET @category = 'MINOR';
@karthiks
karthiks / inline-scalar-udf.sql
Created November 6, 2021 14:13
inline scalar UDF
CREATE FUNCTION CUBE(@X INT)
RETURNS INT
AS
BEGIN
RETURN @X * @X *@X
END
/*
To execute the above function call it like below
SELECT dbo.CUBE(5)
@karthiks
karthiks / sample-data-gen.sql
Last active October 31, 2021 17:36
Sample Data Generation Script
-- DB to use
use Puzzles;
-- Remove the Table and the SP if it already exists
drop table dbo.generated_table;
drop procedure dbo.addRows;
-- Define the Table to be populated with generated data
CREATE TABLE dbo.generated_table (
id int --PRIMARY KEY
@karthiks
karthiks / case3.ps
Last active September 14, 2021 13:41
Case 3: When you want to list files containing all of texts "abc" AND "pqr" AND "xyz".
Get-ChildItem -Recurse | Select-String -Pattern 'abc' -List | Select-String -Pattern 'pqr' -List | | Select-String -Pattern 'xyz' -List | Select Path
# With pipes '|', we are filtering the result set with additional search terms thus acing like the search for terms are AND conditional.
@karthiks
karthiks / case2.ps
Created September 14, 2021 13:08
Case 2: When you want to list files containing any of texts "abc" or "pqr" or "xyz".
Get-ChildItem -Recurse | Select-String -Pattern 'abc', 'pqr', 'xyz' -List | Select Path
# Select-String commandlet can take an array list of strings that it can search for existence and returns all files that has any of those strings in its content.
@karthiks
karthiks / case1.ps
Created September 14, 2021 13:02
Case 1: When you want to list files containing text "abc".
Get-ChildItem -Recurse | Select-String -Pattern 'abc' -List | Select Path
@karthiks
karthiks / mpm_prefork.conf
Created September 13, 2021 13:01
Config for php deployment that is using mpm_prefork_module for it to work with mod_evasive module
StartServers 10
MinSpareServers 10
MaxSpareServers 10
MaxRequestWorkers 80
MaxConnectionsPerChild 0
@karthiks
karthiks / evasive.conf
Created September 13, 2021 12:57
Minimal workable configuration for mod_evasive
<IfModule mod_evasive20.c>
DOSHashTableSize 3097
DOSPageCount 1
DOSSiteCount 3
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10
#DOSEmailNotify [email protected]
#DOSSystemCommand "su - someuser -c '/sbin/... %s ...'"
#DOSLogDir "/var/log/mod_evasive"