Skip to content

Instantly share code, notes, and snippets.

View ronascentes's full-sized avatar

Rodrigo Nascentes ronascentes

View GitHub Profile
@dfinke
dfinke / Singleton.ps1
Created June 28, 2024 13:50
PowerShell Singleton Pattern: Ensure single instance for shared resource management
# Singleton
class Product {
$Name
Product($name) {
$this.Name = $name
}
}
@dfinke
dfinke / Logger-DecoratorPattern.ps1
Last active July 30, 2024 13:54
PowerShell Decorator Pattern: Enhance Logger with Timestamp and Uppercase
class Logger {
log($message) { # Define a method called "log" that takes a message as input
$message | Out-Host # Output the message to the console
}
}
class TimeStampingLogger : Logger { # Define a class called "TimeStampingLogger" that inherits from "Logger"
$logger # Declare a variable called "logger"
TimeStampingLogger($logger) { # Define a constructor that takes a "logger" as input
@davidfowl
davidfowl / .NET6Migration.md
Last active October 23, 2024 18:30
.NET 6 ASP.NET Core Migration
@IanColdwater
IanColdwater / twittermute.txt
Last active November 17, 2024 02:37
Here are some terms to mute on Twitter to clean your timeline up a bit.
Mute these words in your settings here: https://twitter.com/settings/muted_keywords
ActivityTweet
generic_activity_highlights
generic_activity_momentsbreaking
RankedOrganicTweet
suggest_activity
suggest_activity_feed
suggest_activity_highlights
suggest_activity_tweet
@ronascentes
ronascentes / check_errorlog.sql
Last active November 29, 2016 17:34
Look for usually errors by using xp_readerrrorlog
/*
xp_readerrrorlog - extended stored procedure accepts at least 7 parameters
Value of error log file you want to read: 0 = current, 1 = Archive #1, 2 = Archive #2, etc...
Log file type: 1 or NULL = error log, 2 = SQL Agent log
Search string 1: String one you want to search for
Search string 2: String two you want to search for to further refine the results
Search from start time
Search to end time
Sort order for results: N'asc' = ascending, N'desc' = descending
EXEC xp_readerrorlog 0, 1, NULL, NULL, NULL, NULL, N'desc'
@ronascentes
ronascentes / check_database_space.sql
Last active May 3, 2017 19:16
Like sp_spaceused but much better
USE <db_name>
GO
SELECT SUM((size/128.0))/1024 AS [Total Size in GB],
SUM(CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0)/1024 AS [Space Used in GB],
SUM(size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0)/1024 AS [Available Space in GB],
sum((((size)/128.0) - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0)) / sum(((size)/128.0)) * 100 as '% Available'
FROM sys.database_files WITH (NOLOCK)
--WHERE type = 1 -- log
@ronascentes
ronascentes / find_missing_indexes.sql
Last active October 4, 2016 17:43
Finding missing indexes
-- Find Missing Indexes by Index Advantage
-- Look at index advantage, last user seek time, number of user seeks to help determine source and importance
-- SQL Server is overly eager to add included columns, so beware
-- Do not just blindly add indexes that show up from this query!!!
SET NOCOUNT ON
GO
SELECT TOP 25
DB_NAME(dm_mid.database_id) AS Database_Name,
user_seeks * avg_total_user_cost * (avg_user_impact * 0.01) AS [index_advantage],
dm_migs.last_user_seek AS Last_User_Seek,
@ronascentes
ronascentes / check_advanced_settings.sql
Last active October 28, 2016 13:03
Check SQL Server advanced settings
-- show advanced options
-- cost threshold for parallelism
-- max degree of parallelism
-- max server memory (MB)
-- optimize for ad hoc workloads
SELECT name, description, value, value_in_use
FROM sys.configurations
WHERE configuration_id IN (518,1538,1539,1544,1581)
@ronascentes
ronascentes / enable_trace_flags.sql
Last active October 4, 2016 17:42
Useful trace flags for SQL Server performance improvement
-- Trace flag 1118 turns off mixed page allocations. Preventing mixed page allocations reduces the risk of page latch contention
-- on the SGAM allocation bitmatps that track mixed extents; which Paul says is one of the leading causes for contention in tempdb.
-- When doing allocations for user tables always allocate full extents. Reducing contention of mixed extent allocations
DBCC TRACEON (1118,-1)
-- simply stops SQL Server from writing backup successful messages to the error log.
DBCC TRACEON (3226,-1)
-- Changes to automatic update statistics
DBCC TRACEON (2371,-1)