Skip to content

Instantly share code, notes, and snippets.

View georgepaoli's full-sized avatar

George Paoli georgepaoli

View GitHub Profile
@georgepaoli
georgepaoli / EnvHelper.cs
Last active March 21, 2024 13:02
EnvHelper - Helper to read variables in .env file using C#
public static class EnvHelper
{
public static string ENV_VAR_A => GetEnvVar();
public static string ENV_VAR_B => GetEnvVar();
public static string ENV_VAR_C => GetEnvVar();
private static string GetEnvVar([CallerMemberName] string name = null)
=> Environment.GetEnvironmentVariable(name);
}
@georgepaoli
georgepaoli / ssh-keygen.md
Created October 7, 2021 20:48
Create SSH Key for add in Git severs
  • Windows:

ssh-keygen -o -t rsa -b 4096 -C "email@email.com"

notepad C:\Users\usuario\.ssh\id_rsa

@georgepaoli
georgepaoli / PersistedGrantDb.sql
Created January 20, 2021 11:41
IdentityServer4 SQL scripts for SqlServer: PersistedGrants and DeviceCodes tables
CREATE TABLE "PersistedGrants"
(
"Key" varchar(200) NOT NULL,
"Type" varchar(50) NOT NULL,
"SubjectId" varchar(200),
"SessionId" varchar(100),
"ClientId" varchar(200) NOT NULL,
"Description" varchar(200),
"CreationTime" datetime NOT NULL,
"Expiration" datetime,
@georgepaoli
georgepaoli / detach_ec2_from_asg.py
Created November 5, 2020 02:06
Detach EC2 from ASG for SPOT interruptions events
import boto3
def lambda_handler(event, context):
instanceId = event['detail']['instance-id']
asgName = 'xxx'
ec2client = boto3.client('ec2')
describeTags = ec2client.describe_tags(Filters=[{'Name': 'resource-id','Values':[instanceId]}])
for tag in describeTags['Tags']:
if tag['Key'] == 'aws:autoscaling:groupName':
asgName = tag['Value']
@georgepaoli
georgepaoli / nginx-lua-get-token-body-json.conf
Created May 11, 2020 19:27
Get json field in body request using Lua in NGINX
server {
listen 80;
server_name localhost;
location / {
default_type application/json;
access_by_lua_block {
ngx.req.read_body()
local cjson = require "cjson"
local body = cjson.decode(ngx.req.get_body_data())
@georgepaoli
georgepaoli / Dicas Powershell.ps1
Created April 24, 2020 00:56
Comando uteis no Powershell
# clear IIS requestLimits
Get-IISConfigSection "system.webServer/security/requestFiltering" -CommitPath "Default Web Site" | Get-IISConfigElement -ChildElementName 'requestLimits' | Remove-IISConfigElement -Confirm:$false
# change IIS requestLimits
$requestFiltering = Get-IISConfigSection -CommitPath 'Default Web Site' -SectionPath 'system.webServer/security/requestFiltering'
$requestLimits = Get-IISConfigElement -ConfigElement $requestFiltering -ChildElementName 'requestLimits'
Set-IISConfigAttributeValue -ConfigElement $requestLimits -AttributeName "maxAllowedContentLength" -AttributeValue 209715200
# change IIS requestLimits by xml
$file = 'C:\inetpub\wwwroot\web.config'
@georgepaoli
georgepaoli / table sizes in MSSQL.sql
Created April 10, 2020 21:08
Tamanho das tabelas no MSSQL
-- Fonte: https://stackoverflow.com/a/7892349/2076784
SELECT
t.NAME AS TableName,
s.Name AS SchemaName,
p.rows,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
CAST(ROUND(((SUM(a.total_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS TotalSpaceMB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
CAST(ROUND(((SUM(a.used_pages) * 8) / 1024.00), 2) AS NUMERIC(36, 2)) AS UsedSpaceMB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB,
@georgepaoli
georgepaoli / Database sizes in MSSQL.sql
Created April 10, 2020 21:05
Tamanho dos bancos no SQL Server
-- Fonte: https://www.c-sharpcorner.com/blogs/check-database-size-in-sql-server1
SELECT sys.databases.name,
CONVERT(VARCHAR,SUM(size)*8/1024)+' MB' AS [Total disk space]
FROM sys.databases
JOIN sys.master_files
ON sys.databases.database_id=sys.master_files.database_id
GROUP BY sys.databases.name
ORDER BY sys.databases.name
@georgepaoli
georgepaoli / stpVerifica_Locks.sql
Created April 10, 2020 21:02
Identificar Lock no MSSQL
-- Fonte: https://www.dirceuresende.com/blog/sql-server-como-identificar-locks-blocks-e-sessoes-bloqueadoras/
IF (OBJECT_ID('dbo.stpVerifica_Locks') IS NULL) EXEC('CREATE PROCEDURE stpVerifica_Locks AS SELECT 1')
GO
ALTER PROCEDURE [dbo].[stpVerifica_Locks]
AS
BEGIN
SET NOCOUNT ON
@georgepaoli
georgepaoli / DictionaryProxy.cs
Created December 20, 2019 20:14
Safe way for get using Dictonary
public class DictionaryProxy<TKey, TValue>: Dictionary<TKey, TValue>
{
private Dictionary<TKey, TValue> _data;
public DictionaryProxy(Dictionary<TKey, TValue> data = null)
{
_data = data ?? new Dictionary<TKey, TValue>();
}
public TValue this[TKey key]