Skip to content

Instantly share code, notes, and snippets.

View alex-mtx's full-sized avatar

Alexander Molinari alex-mtx

View GitHub Profile
@alex-mtx
alex-mtx / console.readline.shortcut.snippet
Last active November 14, 2019 06:30
Console.ReadLine() shortcut
<!-- save it under %USERPROFILE%\Documents\Visual Studio 2015\Code Snippets\Visual C#\My Code Snippets. -->
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Insert Console.ReadLine()</Title>
<Shortcut>crl</Shortcut>
<Description>Code snippet for Console.ReadLine</Description>
<Author>Stack Overflow User</Author>
<SnippetTypes>
@alex-mtx
alex-mtx / Count-Ports.ps1
Created July 20, 2016 15:12
Detecting Port Exhaustion on Windows via PowerShell
# originally posted on msdn: https://blogs.msdn.microsoft.com/debuggingtoolbox/2010/10/11/powershell-script-troubleshooting-for-port-exhaustion-using-netstat/
## Original author: frank.taglianetti@microsoft.com
## Displays port counts per IP address
## Parameters = none
## Modified 12/6/2011 to include Windows Vista or later
## TCP Parameters documented in http://support.microsoft.com/kb/953230
function MaxNumOfTcpPorts #helper function to retrive number of ports per address
{
<log4net debug="false">
<appender name="INFOFileAppender" type="log4net.Appender.RollingFileAppender">
<!--<level value="INFO" />-->
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="INFO" />
<param name="LevelMax" value="FATAL" />
</filter>
<file value="log\log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
@alex-mtx
alex-mtx / MSSQL_List_Plan_Cache.sql
Last active January 27, 2017 07:05
This query shows the plan cache for a given procedure in a given database
-- original source: http://www.sommarskog.se/query-plan-mysteries.html
-- replace object_id and db_id as needed
-- Reminder: You need the server-level permission VIEW SERVER STATE to run queries against the plan cache
SELECT qs.plan_handle, a.attrlist
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) est
CROSS APPLY (SELECT epa.attribute + '=' + convert(nvarchar(127), epa.value) + ' '
FROM sys.dm_exec_plan_attributes(qs.plan_handle) epa
WHERE epa.is_cache_key = 1
ORDER BY epa.attribute
@alex-mtx
alex-mtx / SetOptions.sql
Created January 27, 2017 07:22
Function to translate the set_options attribute in sys.dm_plan_exec_attributes.
-- Source http://www.sommarskog.se/query-plan-mysteries/setoptions.sql
-- Function to translate the set_options attribute in sys.dm_plan_exec_attributes.
-- Written by Erland Sommarskog, 2011-01-02.
-- Usage: pass to it the set of options of a given cache plan entry: SELECT Set_option FROM setoptions (4347) ORDER BY Set_option
CREATE FUNCTION dbo.setoptions (@setopts int) RETURNS TABLE AS
RETURN
WITH
L0 AS(SELECT 1 AS c UNION ALL SELECT 1),
L1 AS(SELECT 1 AS c FROM L0 AS A, L0 AS B),
L2 AS(SELECT 1 AS c FROM L1 AS A, L1 AS B),
@alex-mtx
alex-mtx / list_sizes.sql
Created February 17, 2017 16:12
List size of tables and indexes over all databases
#https://www.sqlservercentral.com/Forums/Topic1479951-392-1.aspx
IF OBJECT_ID('tempdb..#indexInfo') IS NOT NULL
DROP TABLE #indexInfo;
SELECT TOP 0
t.TABLE_CATALOG AS db,
t.TABLE_SCHEMA AS SchemaName,
OBJECT_NAME(i.OBJECT_ID) AS TableName,
ISNULL(i.name,'<HEAP>') AS IndexName,
i.index_id AS IndexID,
@alex-mtx
alex-mtx / git.squash.master.txt
Created September 4, 2017 13:32
Git squash made simple for Master
Thanks to: https://stackoverflow.com/a/5201642/1456567
You can do this fairly easily without git rebase or git merge --squash. In this example, we'll squash the last 3 commits.
If you want to write the new commit message from scratch, this suffices:
git reset --soft HEAD~3 &&
git commit
If you want to start editing the new commit message with a concatenation of the existing commit messages (i.e. similar to what a pick/squash/squash/…/squash git rebase -i instruction list would start you with), then you need to extract those messages and pass them to git commit: