Skip to content

Instantly share code, notes, and snippets.

View karthiks's full-sized avatar
😄
Playing with GraphQL

Karthik Sirasanagandla karthiks

😄
Playing with GraphQL
View GitHub Profile
@karthiks
karthiks / PowershellCheatsheet.ps
Created August 15, 2023 17:58
Powershell Cheatsheet
# Windows IP Config
ipconfig
Get-NetIPAddress -AddressFamily IPV4 -InterfaceAlias Wi-Fi | Select IPAddress
# When you want to download a list of files in files.txt having header as `sources,`
Import-Csv .\files.txt | Start-BitsTransfer
# Ping equivalent in PS
Test-Connection -ComputerName (hostname) -Count 1
@karthiks
karthiks / BashScriptToSetupDemoRNProjectUsingExpo.sh
Created August 31, 2022 16:03
Bash script to setup Demo React Native project on Ubuntu OS
# Install Expo (for easy creation, bundling and maintenance of project for cross-platform)
npm i -g expo-cli
# Getting dirty with Expo
expo --help # to see commands list
expo register # to sign-up with the site
expo login
expo logout
expo login
expo whoami
@karthiks
karthiks / Windows11FirewallForWSL2ExpoDevServer.ps
Created August 31, 2022 15:57
Windows 11 Firewall setup for communication with Expo Dev Server in WSL2
# To get Env Variables available in Powershell
Get-ChildItem -Path Env:\
# To get host IP. See value for IPv4Address
Get-NetIPConfiguration
# Show Current Firewall Settings
netsh interface portproxy show v4tov4
# Reset/Clear All Firewall Settings
@karthiks
karthiks / upgrade-my-apache-http-server.sh
Created December 27, 2021 17:23
Apache HTTP Server Upgrade Script
# Step 1 : Take backup of current apache2 installation directory
sudo cp -r /etc/apache2 /etc/apache2_bkup
# Step 2 : Stop Apache2
sudo service apache2 stop
# Step 3 : Upgrade Apache2
# Warning: When prompted by the upgrade script asking if you would like to replace the existing config file with newer one, say NO!.
# If you in a hurry select yes, don't forget to replace it with one from the backup you took in step 1.
sudo apt update
@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.